ggplot2与scale_brewer相反的顺序 [英] ggplot2 reverse order of scale_brewer

查看:105
本文介绍了ggplot2与scale_brewer相反的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这是一件非常简单的事情,但它花了我> 30分钟而没有找到答案。



如何反转颜色顺序?通过查看 scale_brewer 的文档,我想它可以是 formatter = 参数可疑。我传递了'rev',然后 rev ,但它们没有任何影响(没有错误消息,只是忽略了)。

解决方案

我想你可能想使用 brewer.pal 直接使用 scale_colour_manual

  ggplot(mtcars,aes(x = $ m 


$(
$)
$ $ b

然后您可以 rev 那里颜色的顺序。

从ggplot版本2.0.0开始,现在有一种更直接的方法可以做到这一点,请参阅下面的@pbaylis的答案。


Seemingly a very simple thing to do but it took me >30min without finding answer.

How do I reverse the order of colors? By looking at documentation for scale_brewer, i figured it can be formatter= argument being suspicious. I passed 'rev' and then rev, but they have no effect (no error message, just ignored).

解决方案

I think you probably want to select the colors using brewer.pal directly and then use scale_colour_manual:

ggplot(mtcars,aes(x = mpg, y = disp)) + 
    geom_point(aes(colour = factor(cyl))) + 
    scale_colour_manual(values = rev(brewer.pal(3,"BuPu")))

Then you can rev the order of the colors there.

As of version 2.0,0 of ggplot there is now a more direct way to do this, see the answer by @pbaylis below.

这篇关于ggplot2与scale_brewer相反的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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