繁体   English   中英

R-在geom_boxplot(ggplot2)顶部绘制geom_point

[英]R - plotting geom_point on top of geom_boxplot (ggplot2)

我无法绘制geom_point()上的顶层geom_boxplot()层中ggplot2 ,并做了一些调查,并有不似乎是任何报道正是这种性质的问题。 我的数据集中有3个因素: namegenotyperegion ,我的反应变量是volume 我有工作代码来生成包含两个图层的图。 问题在于,这些点会忽略geom_point()fill因子,而不是geom_boxplot()fill因子。 结果是,对于name每个值,所有点均绘制在一组箱形图的中间。 这是我用于构建情节的代码。

meansPlot = ggplot(data=meansData,aes(x=factor(name), y=volume, fill=factor(genotype)))
meansPlot = meansPlot + 
geom_boxplot() +
geom_point() +
facet_wrap( ~ region, scales='free')

对于未创建可复制的数据集,我深表歉意–我还不十分了解模拟数据。 如果没有简单的答案(我希望有一个简单的答案,而且我可能只是想漏掉一些东西),我将添加模拟数据来帮助回答问题。

谢谢!

geom_point()应该使用color属性,而不是fill属性(除非您使用的是异常shape )。 看看这是否适合您:

meansPlot = ggplot(data=meansData,aes(x=factor(name), y=volume, fill=factor(genotype)), color = factor(genotype))
meansPlot = meansPlot + 
geom_boxplot() +
geom_point() +
facet_wrap( ~ region, scales='free')

我最终解决了大部分问题。 此代码将geom_point()以与geom_boxplot()内联。

meansPlot = ggplot(data=meansData, aes(x=name, y=volume, fill=genotype, color=genotype))  
meansPlot = meansPlot +
geom_point(position=position_jitterdodge(dodge.width=0.9)) +
geom_boxplot(fill="white", position=position_dodge(width=0.9), alpha=0.5) +
facet_wrap( ~ region, scales='free')

感谢大家的努力。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM