本指南是分級尺度 guide_legend() 指南的一個版本。它的不同之處在於它在按鍵之間正確放置了刻度,並帶有一個小軸以更好地顯示分檔。與 guide_legend() 一樣,它可用於所有非位置美學,盡管顏色和填充默認為 guide_coloursteps() ,並且如果它們以相同的方式映射,它將把美學合並到同一指南中。
用法
guide_bins(
  title = waiver(),
  title.position = NULL,
  title.theme = NULL,
  title.hjust = NULL,
  title.vjust = NULL,
  label = TRUE,
  label.position = NULL,
  label.theme = NULL,
  label.hjust = NULL,
  label.vjust = NULL,
  keywidth = NULL,
  keyheight = NULL,
  axis = TRUE,
  axis.colour = "black",
  axis.linewidth = 0.5,
  axis.arrow = NULL,
  direction = NULL,
  default.unit = "line",
  override.aes = list(),
  reverse = FALSE,
  order = 0,
  show.limits = NULL,
  ...
)
參數
- title
 - 
指示指南標題的字符串或表達式。如果是
NULL,則不顯示標題。默認情況下 (waiver()),比例對象的名稱或labs()中指定的名稱用作標題。 - title.position
 - 
表示標題位置的字符串。 "top"(垂直參考線默認)、"bottom"、"left"(水平參考線默認)或 "right." 之一
 - title.theme
 - 
用於渲染標題文本的主題對象。通常需要
element_text()對象。默認情況下,主題由theme()或主題中的legend.title指定。 - title.hjust
 - 
指定標題文本的水平對齊方式的數字。
 - title.vjust
 - 
指定標題文本垂直對齊的數字。
 - label
 - 
合乎邏輯的。如果
TRUE則繪製標簽。如果FALSE則標簽不可見。 - label.position
 - 
指示標簽位置的字符串。 "top"、"bottom"(水平參考線默認)、"left" 或 "right"(垂直參考線默認)之一。
 - label.theme
 - 
用於渲染標簽文本的主題對象。通常需要
element_text()對象。默認情況下,主題由theme()中的legend.text指定。 - label.hjust
 - 
指定標簽文本水平對齊的數字。對於表達式,標準文本的默認值是 0(左對齊)和 1(右對齊)。
 - label.vjust
 - 
指定標簽文本垂直對齊的數字。
 - keywidth
 - 
指定圖例鍵寬度的數字或
grid::unit()對象。默認值為theme()中的legend.key.width或legend.key.size。 - keyheight
 - 
指定圖例鍵高度的數字或
grid::unit()對象。默認值為theme()中的legend.key.height或legend.key.size。 - axis
 - 
邏輯性強。是否應該沿著導軌繪製小軸
 - axis.colour, axis.linewidth
 - 
軸外觀的圖形規範。
 - axis.arrow
 - 
調用
arrow()以指定軸線末端的箭頭,從而顯示開區間。 - direction
 - 
指示引導方向的字符串。 "horizontal" 或 "vertical." 之一
 - default.unit
 - 
對於
keywidth和keyheight表示grid::unit()的字符串。 - override.aes
 - 
指定圖例鍵的美觀參數的列表。請參閱詳細信息和示例。
 - reverse
 - 
合乎邏輯的。如果
TRUE,則圖例的順序相反。 - order
 - 
小於 99 的正整數,指定該指南在多個指南中的順序。這控製多個指南的顯示順序,而不是指南本身的內容。如果為 0(默認),則順序由秘密算法確定。
 - show.limits
 - 
邏輯性強。是否應該用標簽和刻度顯示刻度的限製。默認值為
NULL,這意味著它將從刻度中獲取值。如果labels作為值向量給出,則忽略此參數。如果breaks中也給出了一個或兩個限製,則無論show.limits的值如何,都會顯示該限製。 - ...
 - 
被忽略。
 
與離散刻度一起使用
本指南旨在顯示分箱數據並與 ggplot2 的分箱比例一起使用。然而,有時需要在單獨的步驟中執行分箱,作為統計數據的一部分(例如 stat_contour_filled() )或在可視化之前。如果您想將本指南用於離散數據,則級別必須遵循 base::cut() 實現的命名方案。這意味著 bin 必須編碼為 "(<lower>, <upper>]",其中 <lower> 給出 bin 的下限,<upper> 給出上限(也接受 "[<lower>, <upper>)")。如果您使用 base::cut() 執行分箱,一切都應該按預期工作,如果沒有,可能需要一些重新編碼。
也可以看看
其他指南:guide_colourbar()、guide_coloursteps()、guide_legend()、guides()
例子
p <- ggplot(mtcars) +
  geom_point(aes(disp, mpg, size = hp)) +
  scale_size_binned()
# Standard look
p
# Remove the axis or style it
p + guides(size = guide_bins(axis = FALSE))
p + guides(size = guide_bins(show.limits = TRUE))
p + guides(size = guide_bins(
  axis.arrow = arrow(length = unit(1.5, 'mm'), ends = 'both')
))
# Guides are merged together if possible
ggplot(mtcars) +
  geom_point(aes(disp, mpg, size = hp, colour = hp)) +
  scale_size_binned() +
  scale_colour_binned(guide = "bins")
相關用法
- R ggplot2 guide_legend 圖例指南
 - R ggplot2 guide_axis 軸導軌
 - R ggplot2 guide_coloursteps 離散顏色條指南
 - R ggplot2 guide_colourbar 連續色條指南
 - R ggplot2 guides 為每個尺度設置指南
 - R ggplot2 geom_qq 分位數-分位數圖
 - R ggplot2 geom_spoke 由位置、方向和距離參數化的線段
 - R ggplot2 geom_quantile 分位數回歸
 - R ggplot2 geom_text 文本
 - R ggplot2 get_alt_text 從繪圖中提取替代文本
 - R ggplot2 geom_ribbon 函數區和麵積圖
 - R ggplot2 geom_boxplot 盒須圖(Tukey 風格)
 - R ggplot2 geom_hex 二維箱計數的六邊形熱圖
 - R ggplot2 geom_bar 條形圖
 - R ggplot2 geom_bin_2d 二維 bin 計數熱圖
 - R ggplot2 ggplot 創建一個新的ggplot
 - R ggplot2 geom_jitter 抖動點
 - R ggplot2 geom_point 積分
 - R ggplot2 geom_linerange 垂直間隔:線、橫線和誤差線
 - R ggplot2 ggsf 可視化 sf 對象
 - R ggplot2 geom_blank 什麽也不畫
 - R ggplot2 ggsave 使用合理的默認值保存 ggplot (或其他網格對象)
 - R ggplot2 ggtheme 完整的主題
 - R ggplot2 geom_path 連接觀察結果
 - R ggplot2 geom_violin 小提琴情節
 
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 A binned version of guide_legend。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
