本文介绍了在ggplot2 for R中,如何反转条形颜色的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ggplot2中有一个简单的条形图。我为我的酒吧使用灰色比例;默认的顺序是从左到右最黑到最亮。这是我的代码的样子:

  ggplot.3plus< -ggplot(summary.3plus,aes(x = sp1,y = fract.mean,fill = age.cat))+ 
geom_bar(position = position_dodge())+ coord_cartesian(ylim = c(1,1.175))+
geom_errorbar(aes(ymin = fract.mean -se,ymax = fract.mean + se),
width = .2,#误差条的宽度
position = position_dodge(.9))
ggplot.3plus< -ggplot。 3plus + scale_fill_grey()

我想将灰色的颜色顺序从最亮变为最暗从左到右,同时保持酒吧本身的顺序。我用来反转颜色渐变顺序的代码看起来并不奏效。 解决方案

更容易一个可重复的例子,但怎么样:

  y + scale_fill_grey(start = 0.8,end = 0.2)


I have a simple bar graph in ggplot2. I am using the "grey" scale for my bars; the default order is darkest to lightest from left to right. Here's what my code looks like:

  ggplot.3plus<-ggplot(summary.3plus, aes(x=sp1, y=fract.mean, fill=age.cat)) +
  geom_bar(position=position_dodge())+ coord_cartesian(ylim = c(1, 1.175))+
  geom_errorbar(aes(ymin=fract.mean-se, ymax=fract.mean+se),
                width=.2,                    # Width of the error bars
                position=position_dodge(.9))
  ggplot.3plus<-ggplot.3plus+scale_fill_grey()

I would like to change the color order of the greys to lightest to darkest from left to right, while keeping the bars themselves in the same order. The code I'm using to reverse the order of the color ramp doesn't seem to be working.

解决方案

It would be easier with a reproducible example, but what about:

y + scale_fill_grey(start=0.8, end=0.2)

这篇关于在ggplot2 for R中,如何反转条形颜色的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:04