我想绘制一个带有点的“组合”条形图。 考虑到以下虚拟数据:组合条形图和ggplot2中的点
library(ggplot2)
library(gridExtra)
library(dplyr)
se <- function(x){sd(x)/sqrt(length(x))}
p1 <- ggplot(mtcars, aes(y=disp, x=cyl, fill=cyl))
p1 <- p1 + geom_point() + theme_classic() + ylim(c(0,500))
my_dat <- summarise(group_by(mtcars, cyl), my_mean=mean(disp),my_se=se(disp))
p2 <- ggplot(my_dat, aes(y=my_mean,x=cyl,ymin=my_mean-my_se,ymax=my_mean+my_se))
p2 <- p2 + geom_bar(stat="identity",width=0.75) + geom_errorbar(stat="identity",width=0.75) + theme_classic() + ylim(c(0,500))
最后的情节看起来应该:
或'geom_point(数据= mtcars,AES(Y = DISP,X = CYL-.5,补= CYL))'以获得所需的偏移。 – lukeA 2015-03-02 21:05:35