我从不同的数据框中计算出各列的均值,并将它们放入另一个数据框中以进行绘图。以下是代码:
res <- structure(list(`2012` = 6.86537485268066,
`2013` = 5.91282899425944,
`2014` = 4.45070377934188),
.Names = c("2012", "2013", "2014"),
row.names = c(NA, -1L), class = "data.frame")
colors<- c("yellow", "red", "green")
ticks <- c(0,8)
barplot(as.matrix(res), ylim=ticks, ylab="Mean Ratio",
width=0.5, col=colors, xlab="Year", main="Mean ratio per year")
我得到了一个黄色的单色条形图。
同样适用于:
myMat<-matrix(runif(3), ncol=3)
barplot(myMat, col=colors)
为什么呢?我已经用了ggplot
和reshape
做了图形,但还是有些困扰。