我的数据(MafBeta)看起来像(原始数据是1000个人,这里我只显示了前10个):
EuMAF Eubeta
0.11620 -0.000638786
0.02020 0.012226700
0.01515 0.009831800
0.06229 -0.002261970
0.04714 -0.006207810
0.00000 0.000000000
0.42090 -0.008781820
0.00000 0.000000000
0.01852 0.006342230
0.03199 -0.001722920
想要为每个6个平均点添加方块图,我试过这个:
library(dplyr)
library(ggplot2)
forLines <- MafBeta %>% group_by(cut(EuMAF, breaks = 6, labels=F)) %>%
summarise(mean_beta = mean(Afbeta), mean_maf = mean(EuMAF))
p <- ggplot(forLines, aes(x=mean_maf, y=mean_beta))
p + geom_point(size=3) + geom_boxplot(aes(group=cut(MafBeta$EuMAF,breaks=6,labels=F))) +
geom_line(data=forLines,aes(x=mean_maf,y=mean_beta))
错误:美学必须是长度1或与数据(6)相同:group,x,y
有什么建议吗?