当超过6个因子水平时,通过点形状循环 [英] Cycling through point shapes when more than 6 factor levels

查看:695
本文介绍了当超过6个因子水平时,通过点形状循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

geom_point 内使用审美映射 shape 时,当出现的因子数超过6:

形状调色板最多可以处理6个离散值,因为超过6个难以区分;您有15个。请考虑手动指定形状。



我倾向于同意限制不同形状数量的原则,但是当使用形状与颜色相结合这应该不是问题。



有没有一种让ggplot在形状中循环的优雅方法,即设置symbol7 = symbol1等等?现在它只是简单地省略了因子级别大于6的点。



正如你所看到的,你有很多形状的可能性。当您达到> 6时,您必须手动设置数字,以这种方式:

  ggplot(data = dat1,aes(x = x,y = y,group = method,shape = method,color = method))+ 
geom_point()+
scale_shape_manual(values = seq(0,15))

通过这种方式,您将不会有任何警告,您将在图表上获得相应的符号。



更新



Luchonacho指出,有许多新形状可用。请记住,如果你想使用循环来设置它们,不要使用 aes(),因为它会暂时将最后的绘图参考(即仅最后一个循环输入)保存在内存中,只绘制那一个。




When using the aesthetic mapping shape within geom_point, I get the following message when the number of factors present exceeds 6:

"The shape palette can deal with a maximum of 6 discrete values because more than 6 becomes difficult to discriminate; you have 15. Consider specifying shapes manually. if you must have them."

I tend to agree with the principle of limiting the number of distinct shapes, however when using shape in combination with color this should not be a problem.

Is there an elegant way to get ggplot to cycle through shapes, i.e. setting symbol7 = symbol1 etc? Right now it simply omits the points with factor level > 6.

解决方案

as you can see you have many possibilities for shapes. When you reach >6 you have to set the number manually, in this way:

    ggplot(data=dat1, aes(x=x, y=y,group=method,shape=method,color=method))+
    geom_point() +
    scale_shape_manual(values=seq(0,15))

In this way you will have no warnings and you will get the corresponding symbols on the graph

Update

As Luchonacho pointed out there are many new shapes available. Remember that if you want to set them using a loop do not use aes() as it would temporally keep in memory the last plotting reference (i.e. only the last looped input) and plot only that one.

这篇关于当超过6个因子水平时,通过点形状循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆