反转默认比例梯度ggplot2 [英] Reversing default scale gradient ggplot2
问题描述
我是新手,我正在尝试设计热图.这是我的代码:
ggplot(gd,aes(Qcountry,Q6_1_Q6d),order = TRUE)+geom_tile(aes(fill = prob),color ="white")+theme_minimal()+实验室(y =造成流动性的主要原因",x =国家/地区")+主题(axis.text.x = element_text(角度= 90,对齐= 1,对齐= 0.3))+scale_fill_gradient(name =(%)")
哪张图可以生成完美的图表,但我的问题是低水平是深蓝色,而较高的值是浅蓝色,这是不直观的.最常见的方法是使用 rev()
.但就我而言,我不知道该怎么做.因此,是否可以反转此默认比例?
我个人认为,这不像默认设置那样直观.
或者,您可以使用反向比例尺,但是这也会使图例翻转至顶部:
ggplot(忠实,aes(等待,爆发))+geom_raster(aes(填充=密度))+scale_fill_continuous(trans ='reverse')
I am newbie, I am trying to desing a heat map. This is my code:
ggplot(gd, aes(Qcountry, Q6_1_Q6d), order = TRUE) +
geom_tile(aes(fill = prob), colour = "white") +
theme_minimal() +
labs( y = "Main reason for mobility", x = "Country") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.3)) +
scale_fill_gradient(name = "(%)")
Which produces a perfect chart, my problem is low levels are dark blue, and higher values are light blue, which is not intuitive. Most common way to do is use rev()
. But in my case I dont know how to. So, is it possible to reverse this default scale?
This is the legend
Other question, is there a way to create a scale gradient only with one colour. I mean, scale_fill_gradient/scale_fill_gradientn
need to set a low color and high color (low = "", high = "")
and I want to change the blue by red.
Thanks so much for your support.
?scale_colour_gradient
shows the default values of low = "#132B43"
and high = "#56B1F7"
.
Simply switch those around:
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_continuous(high = "#132B43", low = "#56B1F7")
Personally, I think this is less intuitive than the default.
Alternatively, you can use a reverse scale, but this will also flip the legend to start at the top:
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_continuous(trans = 'reverse')
这篇关于反转默认比例梯度ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!