ggplot产生美观的图表,但我没有魄力去尝试和发布任何ggplot输出然而。
直到一天到来,这里是我如何制作上述图表。我使用名为'gplots'的图形包来获得标准误差线(使用我已计算的数据)。请注意,此代码为每个类/类别提供了两个或更多因素。这需要数据以矩阵形式进入,而“barplot2”函数中的“beside = TRUE”命令可以防止堆叠。
# Create the data (means) matrix
# Using the matrix accommodates two or more factors for each class
data.m <- matrix(c(75,34,19, 39,90,41), nrow = 2, ncol=3, byrow=TRUE,
dimnames = list(c("Factor 1", "Factor 2"),
c("Class A", "Class B", "Class C")))
# Create the standard error matrix
error.m <- matrix(c(12,10,7, 4,7,3), nrow = 2, ncol = 3, byrow=TRUE)
# Join the data and s.e. matrices into a data frame
data.fr <- data.frame(data.m, error.m)
# load library {gplots}
library(gplots)
# Plot the bar graph, with standard errors
with(data.fr,
barplot2(data.m, beside=TRUE, axes=T, las=1, ylim = c(0,120),
main=" ", sub=" ", col=c("gray20",0),
xlab="Class", ylab="Total amount (Mean +/- s.e.)",
plot.ci=TRUE, ci.u=data.m+error.m, ci.l=data.m-error.m, ci.lty=1))
# Now, give it a legend:
legend("topright", c("Factor 1", "Factor 2"), fill=c("gray20",0),box.lty=0)
这是很简单的简,美观,但似乎是大多数期刊/老教授们希望看到的。
我会发布这些示例数据生成的图表,但这是我在网站上的第一篇文章。抱歉。一个应该能够复制粘贴整个事情(安装“gplots”包后)没有问题。
你刚才打我一个!我昨天阅读了www.imachordata.com的帖子,甚至通过电子邮件发送给了一位前同事。 – 2009-09-16 16:02:49
这是R博客中的一个小世界。 :)我最近开始关注R星球(http://planetr.stderr.org/),这有点令人难以置信。 – Shane 2009-09-16 16:18:49
我需要停止懒惰,并开始维护R博客列表。 – 2009-09-16 18:21:53