基於gray.colors()。這是相當於 scale_colour_gradient() 的黑白圖。
用法
scale_colour_grey(
  ...,
  start = 0.2,
  end = 0.8,
  na.value = "red",
  aesthetics = "colour"
)
scale_fill_grey(
  ...,
  start = 0.2,
  end = 0.8,
  na.value = "red",
  aesthetics = "fill"
)
參數
- ...
 - 
參數傳遞給
discrete_scalepalette- 
調色板函數,當使用單個整數參數(比例中的級別數)調用時,返回它們應采用的值(例如
scales::hue_pal())。 breaks- 
之一:
 limits- 
之一:
- 
NULL使用默認比例值 - 
定義可能的比例值及其順序的字符向量
 - 
接受現有(自動)值並返回新值的函數。還接受 rlang lambda 函數表示法。
 
 - 
 drop- 
是否應該從量表中省略未使用的因子水平?默認值
TRUE使用數據中出現的級別;FALSE使用因子中的所有級別。 na.translate- 
與連續尺度不同,離散尺度可以輕鬆顯示缺失值,並且默認情況下會這樣做。如果要從離散尺度中刪除缺失值,請指定
na.translate = FALSE。 scale_name- 
應用於與該比例關聯的錯誤消息的比例名稱。
 name- 
秤的名稱。用作軸或圖例標題。如果
waiver()(默認值),則比例名稱取自用於該美學的第一個映射。如果是NULL,則圖例標題將被省略。 labels- 
之一:
 guide- 
用於創建指南或其名稱的函數。有關詳細信息,請參閱
guides()。 expand- 
對於位置刻度,範圍擴展常量的向量,用於在數據周圍添加一些填充,以確保它們放置在距軸一定距離的位置。使用便捷函數
expansion()生成expand參數的值。默認情況下,對於連續變量,每側擴展 5%,對於離散變量,每側擴展 0.6 個單位。 position- 
對於位置刻度,軸的位置。
left或right表示 y 軸,top或bottom表示 x 軸。 super- 
用於構造比例的超類
 
 - start
 - 
調色板低端的灰度值
 - end
 - 
調色板高端的灰度值
 - na.value
 - 
用於缺失值的顏色
 - aesthetics
 - 
字符串或字符串向量,列出了該比例所使用的美學名稱。例如,這可以用於通過
aesthetics = c("colour", "fill")同時將顏色設置應用於colour和fill美學。 
例子
p <- ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(colour = factor(cyl)))
p + scale_colour_grey()
p + scale_colour_grey(end = 0)
# You may want to turn off the pale grey background with this scale
p + scale_colour_grey() + theme_bw()
# Colour of missing values is controlled with na.value:
miss <- factor(sample(c(NA, 1:5), nrow(mtcars), replace = TRUE))
ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(colour = miss)) +
  scale_colour_grey()
ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(colour = miss)) +
  scale_colour_grey(na.value = "green")
相關用法
- R ggplot2 scale_gradient 漸變色階
 - R ggplot2 scale_shape 形狀比例,又稱字形
 - R ggplot2 scale_viridis 來自 viridisLite 的 Viridis 色標
 - R ggplot2 scale_linetype 線條圖案的比例
 - R ggplot2 scale_discrete 離散數據的位置尺度
 - R ggplot2 scale_manual 創建您自己的離散尺度
 - R ggplot2 scale_colour_discrete 離散色階
 - R ggplot2 scale_steps 分級漸變色標
 - R ggplot2 scale_size 麵積或半徑比例
 - R ggplot2 scale_date 日期/時間數據的位置刻度
 - R ggplot2 scale_continuous 連續數據的位置比例(x 和 y)
 - R ggplot2 scale_binned 用於對連續數據進行裝箱的位置比例(x 和 y)
 - R ggplot2 scale_alpha Alpha 透明度比例
 - R ggplot2 scale_colour_continuous 連續色標和分級色標
 - R ggplot2 scale_identity 使用不縮放的值
 - R ggplot2 scale_linewidth 線寬比例
 - R ggplot2 scale_hue 離散數據的均勻間隔顏色
 - R ggplot2 scale_brewer ColorBrewer 的連續、發散和定性色標
 - R ggplot2 stat_ellipse 計算法行數據橢圓
 - R ggplot2 stat_identity 保留數據原樣
 - R ggplot2 stat_summary_2d 以二維形式進行分類和匯總(矩形和六邊形)
 - R ggplot2 should_stop 在示例中用於說明何時應該發生錯誤。
 - R ggplot2 stat_summary 總結唯一/分箱 x 處的 y 值
 - R ggplot2 stat_sf_coordinates 從“sf”對象中提取坐標
 - R ggplot2 stat_unique 刪除重複項
 
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Sequential grey colour scales。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
