我在让我的 ggplot alpha 对我的情节足够暗时遇到了一些问题。
示例代码:
ggplot(mtcars, aes(x=mpg, color=factor(gear), alpha=factor(carb))) + stat_ecdf()
如您所见,无论何时carb == 1
,都很难看到情节元素。在我的真实世界数据集中,颜色因子有四个级别,alpha 因子有两个级别。我希望 alpha 的颜色稍微浅一些,但比该示例中的颜色更明显)。
正如评论中的用户所建议的那样,您可以通过将 arange
或特定集指定为breaks
来调整 alpha 比例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(gear), color=factor(carb))) +
stat_ecdf()
不过,为了可读性,刻面可能是更好的选择。
ggplot(mtcars, aes(x=mpg, color=factor(carb))) +
stat_ecdf() + facet_wrap(~gear, nrow=3)