【发布时间】:2019-09-19 18:29:27
【问题描述】:
我需要用三个土壤深度(行(A1、A2、A3))绘制不同耕作水平(列)的侵蚀值。我希望所有这些都显示为单个图中的条形图。
这是一个可重现的例子:
a<- matrix(c(1:36), byrow = T, ncol = 4)
rownames(a)<-(c("A1","B1","C1","A2","B2","C2","A3","B3","C3"))
colnames(a)<-(c("Int_till", "Redu_till", "mulch_till", "no_till"))
barplot(a[1,], xlab = "A1", ylab = "Erosion")
barplot(a[4,], xlab = "A2", ylab = "Erosion")
barplot(a[7,], xlab = "A3", ylab = "Erosion")
##I want these three barchart side by side in a single plot
## for comparison
### and need similar plots for all the "Bs" and "Cs"
### Lastly, i want these three plots in the same page.
我看到人们在 ggplot(用于线条)中使用“填充”来做类似的事情,并指定可以很好地将图表区分为不同类别的因素,但我尝试这样做但总是遇到错误,可能是因为我的数据是连续的。
如果有任何机构可以在这两件事上帮助我.. 这将是一个很大的帮助。我会很感激的。
谢谢!
【问题讨论】:
-
如果你在
ggplot做这个,可以用facet_wrap或者base R,改par -
你可以做
par(mfrow = c(3, 1))然后运行barplot语句 -
你需要
library(reshape2); library(ggplot2);> melt(a) %>% ggplot(., aes(x = Var2, y = value, fill = Var1)) + geom_bar(stat = 'identity', position = position_dodge2(preserve = "single"))