如何更改 ggplot 图中某个因素的 1 个级别的美观和外观
我在 x 轴上绘制一组离散水平的因子,并在 y 轴上绘制它们的相关平均结果值,如下所示:
ggplot(data, aes(item, outcome)) +
stat_summary(fun.y=mean, geom="point", colour="red",size=3)
我的最后一个“项目”是平均值,我想这样做视觉上弹出。
- 是否可以只为一个级别的因子项设置不同的形状或颜色?
- 是否有可能对一个因素的一个水平进行物理转移或创建障碍(就好像它是一个方面)?
I'm plotting a set of discrete levels of a factor on the x axis and their relevant mean outcome value on the y-axis, something like this:
ggplot(data, aes(item, outcome)) +
stat_summary(fun.y=mean, geom="point", colour="red",size=3)
the last 'item' I have is the mean, and I would like to make this pop out visually.
- Is it possible to have a different shape or color for just one level of the factor item?
- Is it possible to physically shift or create a barrier for one level of a factor (as if it were a facet)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过向具有两个级别的数据框添加另一个因素来轻松地使最后一个级别具有不同的颜色(或形状):您想要的级别和其他所有级别。例如:
然后您在
aes
中设置颜色美感,而不是全局设置。一旦你有了这个附加变量,你也可以对其进行分面(编辑以反映@Ben Bolker的评论):You can easily make the last level a different color (or shape) by adding another factor to your data frame that has two levels: the one you want, and everything else. For instance:
Then you set the colour aesthetic in
aes
rather than globally. Once you have this additional variable, you can also facet on it (edited to reflect @Ben Bolker's comment):