我在使用 geom_bars 时遇到问题,其中当我在 y 轴上指定限制时不呈现条形图。我相信以下应该重现问题:
data <- structure(list(RoleCond = structure(c(1L, 1L, 2L, 2L), .Label = c("Buyer", "Seller"), class = "factor"),
ArgCond = structure(c(1L, 2L, 1L, 2L), .Label = c("No Argument", "Argument"), class = "factor"),
mean = c(2210.71428571429, 2142.70833333333, 2282.40740740741, 2346.2962962963),
se = c(20.1231042081511, 16.7408757749718, 20.1471554637891, 15.708092540868)),
.Names = c("RoleCond", "ArgCond", "mean", "se"), row.names = c(NA, -4L), class = "data.frame")
library(ggplot2)
ggplot(data=data, aes(fill=RoleCond, y=mean, x=ArgCond)) +
geom_bar(position="dodge", stat="identity") +
geom_errorbar(limits, position=dodge, width=0.1, size=.75) +
scale_y_continuous(limits=c(2000,2500))
这给了我这个
没有指定限制的相同代码可以正常工作。 geom_errorbar() 似乎与问题无关,但它确实说明了应该显示条的位置。
我试过使用
coord_cartesian(ylim=c(2000,2500))
这适用于限制 yaxis 并显示条形,但轴标签弄乱了,我不明白我在做什么。感谢您的任何建议! (我使用 R 2.15.0 和 ggplot2 0.9.0)
最佳答案
关于r - 指定 ylim 时不显示 geom_bar 条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10365167/