如何在R中编辑镶嵌面包裹条形图

如何在R中编辑镶嵌面包裹条形图,r,ggplot2,R,Ggplot2,我这里有一个图表: 要更改颜色,您需要告诉ggplot站点是一个因素(正如@user20650在评论中指出的) 由于在facet\u wrap() 要去掉图形底部的as.numeric(row)标签,您可以使用theme()语句指定不需要文本。您还可以通过添加带有p的空白标签来实现这一点,该列列出了我得到的行错误:error:id变量未在数据中找到:row,因为Floor0提到您的代码没有完全运行,但要获得每个站点不同的填充,您需要将其定义为因子ie填充=因子(站点)。目前它被视为连续的(整数

我这里有一个图表:


要更改颜色,您需要告诉ggplot站点是一个因素(正如@user20650在评论中指出的)

由于在
facet\u wrap()


要去掉图形底部的as.numeric(row)标签,您可以使用
theme()
语句指定不需要文本。您还可以通过添加带有
p的空白标签来实现这一点,该列列出了我得到的行错误:
error:id变量未在数据中找到:row
,因为Floor0提到您的代码没有完全运行,但要获得每个站点不同的
填充
,您需要将其定义为
因子
ie
填充=因子(站点)
。目前它被视为连续的(整数)。抱歉。这段代码需要先进入dframe1$row,非常感谢您的回答。我的意思是(关于迷你轴),我怎样才能给它们添加单独的标签?也就是说,我可以指定单位等。我还想更改R中的标题,我尝试使用colnames()但不起作用。@KB2我更新了答案,以包括如何更改面标签。第一个问题我不确定,也没有一个简单的答案。祝你好运
dframe1$row <- row.names(dframe1)
library(reshape2)
dframe2 <- melt(dframe1, id=c("Site", "row"))
ggplot(dframe2, aes(x=as.numeric(row), fill=Site, y=value)) + geom_bar(stat="identity") +       facet_wrap(~variable, scales="free")
structure(list(Site = c(2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 
4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L), weight = c(0.193, 0.249, 0.263, 
0.262, 0.419, 0.204, 0.311, 0.481, 0.326, 0.657, 0.347, 0.239, 
0.416, 0.31, 0.314, 0.277, 0.302, 0.403), cell.count = c(2530000, 
729000, 336000, 436000, 292000, 0, 2e+05, 6450000, 2e+05, 18700000, 
7430000, 9920000, 22700000, 21600000, 227000, 169000, 5e+05, 
283000), eleocyte = c(1270000, 17, 7.3, 264000, 0, 0, 2e+05, 
0, 2e+05, 2270000, 0, 9920000, 22700000, 442, 153000, 169000, 
5e+05, 283000), lambda.max = c(459L, 459L, 459L, 459L, 462L, 
462L, 462L, 462L, 462L, 465L, 465L, 465L, 465L, 490L, 490L, 475L, 
475L, 475L), avepb.ppm = c(390.2, 373.3, 340.13, 403.2, 248.53, 
206.7, 238.5, 190.6, 597.2, 206.8, 174.4, 186.3, 138.5, 269.55, 
58.1, 5.225, 4.02, 6.85), aveworm.pb.ppm = c(9.59, 9.446, 4.193, 
21.9, 1.66, 7.415, 13.11, 3.01, 51.5, 5.985, 4.705, 26.38, 2.38, 
4.44, 4.67, 0.11, 0.085, 0.096), aveworm.g = c(0.09125, 0.264, 
14.699, 0.2425, 0.4793, 0.051, 0.0635, 0.0465, 0.2645, 0.0559, 
0.0795, 0.05765, 0.0846, 0.457, 0.0625, 0.0535, 0.1576, 0.16)), .Names = c("Site", 
"weight", "cell.count", "eleocyte", "lambda.max", "avepb.ppm", 
"aveworm.pb.ppm", "aveworm.g"), class = "data.frame", row.names = c(NA, 
-18L))
library(ggplot2)
p <- ggplot(dframe2, aes(x = as.numeric(row), fill = as.factor(Site), y = value))
p <- p + geom_bar(stat = "identity") + facet_wrap(~variable, scales = "free")
p <- p + scale_fill_discrete("Site")
p <- p + theme(axis.title.x = element_blank())
p
levels(dframe2$variable) <- c("Weight", "Cell Count", "Eleocyte", "Lambda",
                              "Average PPM", "Average PB PPM", "Average G")