简体   繁体   English

设置 ggthemese 连续刻度的中点

[英]Setting midpoint for ggthemese continuous scales

In ggplot2 , we can use the midpoint argument in scale_fill_gradient2() to set the midpoint of divergence, however this does not exist when I try to use color themes from ggthemes such as scale_fill_gradient2_tableau()ggplot2中,我们可以使用scale_fill_gradient2()中的midpoint参数来设置发散的中点,但是当我尝试使用来自ggthemes的颜色主题(例如scale_fill_gradient2_tableau()

# A tibble: 6 x 2
  Year     Value
  <chr>    <dbl>
1 2002   0.0109 
2 2001  -0.0273 
3 2000   0.0113 
4 1999   0.0148 
5 1998   0.00841
6 1997   0.0361 

ggplot(df, aes(x = Year, y = Value)) +
  geom_col(aes(fill = Value)) +
  scale_fill_gradient2_tableau()

I would like the midpoint to be at 0 but now it is at 0.75.我希望中点为 0,但现在为 0.75。

在此处输入图像描述

You can centre the colorbar at zero by specifying limits that are equally distant from zero, eg您可以通过指定与零距离相等的限制来将颜色条居中于零,例如

library(tidyverse)
#install.packages("ggthemes")
library(ggthemes)

Year <- list("2002", "2001", "2000", "1999", "1998", "1997")
Value <- list(0.0109, -0.0273, 0.0113, 0.0148, 0.00841, 0.0361)
df <- do.call(rbind, Map(data.frame, Year=Year, Value=Value))

ggplot(df, aes(x = Year, y = Value)) +
  geom_col(aes(fill = Value)) +
  scale_fill_gradient2_tableau(limits = c(-0.04, 0.04))

中点居中的示例图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM