ggplot:调整阿尔法/填充两个因素cdf [英] ggplot: adjusting alpha/fill two factors cdf

查看:295
本文介绍了ggplot:调整阿尔法/填充两个因素cdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题让我的ggplot alpha对我的情节足够黑暗。



示例代码:

  ggplot(mtcars,aes(x =颜色=因子(齿轮),alpha =因子(碳水化合物))+ stat_ecdf()



正如你所看到的,每当 carb == 1 时,很难看到情节元素。在我的真实世界数据集中,颜色因子有四个等级,alpha因子有两个等级。我希望alpha的颜色稍浅一些,但比它更容易看到)。 解决方案

p>您可以通过指定范围或特定集间歇 scale_alpha_discrete 。尽管如此,这并没有产生一个很容易理解的结果:

  ggplot(mtcars,aes(x = mpg, color = factor(gear),alpha = factor(carb)))+ 
stat_ecdf()+
scale_alpha_discrete(range = c(0.4,1))



另一个选择是为许多级别的因子保存 color ,并为少数级别的元素选择不同的审美,也许 linetype

  ggplot(mtcars,aes(x = mpg ,linetype = factor(齿轮),color = factor(carb)))+ 
stat_ecdf()



为了便于阅读不过,分面也许是更好的选择。

  ggplot(mtcars,aes(x = mpg,color = factor(carb) ))+ 
stat_ecdf()+ facet_wrap(〜gear,nrow = 3)

< IM g src =https://i.stack.imgur.com/HjX5w.pngalt =在这里输入图片描述>


I'm having some issues getting my ggplot alpha to be sufficiently dark for my plot.

Example code:

ggplot(mtcars, aes(x=mpg, color=factor(gear), alpha=factor(carb))) + stat_ecdf()

As you can see, whenever carb == 1, it's very difficult to see the plot elements. In my real world data set, the factor for color has four levels and the alpha factor has two levels. I was hoping to have the alpha a slightly lighter shade of the color, but more visible than how it's occurring in that example).

解决方案

You can adjust the alpha scale, as the user in the comment suggests, either by specifying a range or a specific set breaks to scale_alpha_discrete. That doesn't produce a very easy-to-read result, though:

ggplot(mtcars, aes(x=mpg, color=factor(gear), alpha=factor(carb))) + 
  stat_ecdf() + 
  scale_alpha_discrete(range=c(0.4, 1))

Another option would be to save color for the many-leveled factor and choose a different aesthetic for the few-leveled one, like maybe linetype

ggplot(mtcars, aes(x=mpg, linetype=factor(gear), color=factor(carb))) + 
  stat_ecdf()

For readability, though, faceting might be a better bet.

ggplot(mtcars, aes(x=mpg, color=factor(carb))) + 
  stat_ecdf() + facet_wrap(~gear, nrow=3)

这篇关于ggplot:调整阿尔法/填充两个因素cdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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