簡體   English   中英

設置 ggthemese 連續刻度的中點

[英]Setting midpoint for ggthemese continuous scales

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()

我希望中點為 0,但現在為 0.75。

在此處輸入圖像描述

您可以通過指定與零距離相等的限制來將顏色條居中於零,例如

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