在单个geom_sina/小提琴图中显示离散变量
我正在尝试使用geom_sina
和geom_violin
创建一个图,其中将所有数据点绘制在一起(一个小提琴形状),并以一个因素为颜色。
但是,当我指定ggplot(mtcars,aes(x =“”,y = mpg,fill = am))
时,该图是根据因子分开的,这就是我想要的避免(图1)。我最接近的是将因子视为连续变量(图2)。但是随后,传说显示一个“填充”条,而不是我想要的离散因子级别。
因此,如果可能的话,我希望在使用因子时停止按颜色分裂,或者如果使用数字进行离散值,则可以通过颜色分裂。
任何帮助都非常感谢:)
I'm trying to create a plot with geom_sina
and geom_violin
where all data points are plotted together (as one violin shape) and are coloured by a factor.
However, when I specify ggplot(mtcars, aes(x = "", y = mpg, fill = am))
, the plot is split according to the factor, which is what I'd like to avoid (plot 1). The closest I've come is treating the factor as a continuous variable (plot 2). But then the legend displays a "fill" bar and not the discrete factor levels I'd like.
So, if possible, I'd like the plot to stop splitting by colour when using a factor, or to overide the legend to discrete values if going with numerics.
Any help is much appreciated : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这就是您要寻找的。使用
group
美学,您可以通过fill
或color
or 或...:注意:您希望点要涂上彩色的 默认分组我切换到
颜色
美学。Maybe this is what you are looking for. Using the
group
aesthetic you could overwrite the default grouping byfill
orcolor
or ...:Note: As you want the points do be colored I switched to the
color
aesthetic.