Guides: axes and legends
The guides (the axes and legends) help readers interpret your plots. Guides are mostly controlled via the scale (e.g. with the limits, breaks, and labels arguments), but sometimes you will need additional cover over the guide apperance. Use guides() or the guide argument to individual scales along with guide_colourbar() or guide_legend().
标记(坐标轴和图例)帮助读者理解图形。标记大多是由规模来控制的(例如,有限制、中断和标签参数),但是有的时候,你需要放一些额外的标记。使用guides()命令或者使用个性化的guides参数,像guide_colourbar() 或者 guide_legend().
guide_colourbar guide_colorbar
(原文链接:http://ggplot2.tidyverse.org/reference/guide_colourbar.html)
Colour bar guide shows continuous color scales mapped onto values. Colour bar is available with scale_fill and scale_colour. For more information, see the inspiration for this function: Matlab's colorbar function.
生成连续的彩条图例
彩色条导图显示连续的颜色标度映射到数值上。彩色条可以来自scale_fill和scale_colour。更多信息参考Matlab的颜色条功能。
代码
guide_colourbar(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, barwidth = NULL, barheight = NULL, nbin = 20, raster = TRUE, ticks = TRUE, draw.ulim = TRUE, draw.llim = TRUE, direction = NULL, default.unit = "line", reverse = FALSE, order = 0, ...)
guide_colorbar(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, barwidth = NULL, barheight = NULL, nbin = 20, raster = TRUE, ticks = TRUE, draw.ulim = TRUE, draw.llim = TRUE, direction = NULL, default.unit = "line", reverse = FALSE, order = 0, ...)
参数
title
A character string or expression indicating a title of guide. If NULL, the title is not shown. By default (waiver), the name of the scale object or the name specified in labs is used for the title.
表示标题的表达式。如果NULL,则没有标题。在默认情况下不显示,将使用scale对象的名称或在实验室中指定的名称作为标题。
title.position
A character string indicating the position of a title. One of "top" (default for a vertical guide), "bottom", "left" (default for a horizontal guide), or "right."
标题位置,上下左右
title.theme
A theme object for rendering the title text. Usually the object of element_text is expected. By default, the theme is specified by legend.title in theme or theme.
呈现标题文本的主题对象。通常需要element_text对象。默认情况下,主题由legend指定。
title.hjust
A number specifying horizontal justification of the title text.
指定标题文本的水平对齐。
title.vjust
A number specifying vertical justification of the title text.
指定标题文本的垂直对齐。
label
logical. If TRUE then the labels are drawn. If FALSE then the labels are invisible.
逻辑性。如果是真的,那么标签就画出来了。如果假的话,标签是看不见的。
label.position
A character string indicating the position of a label. One of "top", "bottom" (default for horizontal guide), "left", or "right" (default for vertical guide).
表示标签位置的字符串。“顶部”、“底部”、“左”或“右”。
label.theme
A theme object for rendering the label text. Usually the object of element_text is expected. By default, the theme is specified by legend.text in theme or theme.
呈现标签文本的主题对象。通常需要element_text对象。默认情况下,主题由legend指定。主题或主题的文本。
label.hjust
A numeric specifying horizontal justification of the label text.
指定标签文本水平对齐。
label.vjust
A numeric specifying vertical justification of the label text.
指定标签文本的垂直对齐。
barwidth
A numeric or a unit object specifying the width of the colorbar. Default value islegend.key.width or legend.key.size in theme or theme.
指定colorbar宽度。默认值是Theme的 islegend.key.width或legend.key.size
barheight
A numeric or a unit object specifying the height of the colorbar. Default value islegend.key.height or legend.key.size in theme or theme.
指定颜色条高度。默认值是Theme的islegend.key.height或legend.key.size
nbin
A numeric specifying the number of bins for drawing colorbar. A smoother colorbar for a larger value.
指定绘制colorbar的箱子数的数字。值越大colorbar越平滑。
raster
A logical. If TRUE then the colorbar is rendered as a raster object. If FALSE then the colorbar is rendered as a set of rectangles. Note that not all graphics devices are capable of rendering raster image.
逻辑。如果是TRUE,那么colorbar被呈现为一个光栅对象。如果FALSE,那么colorbar被呈现为一组矩形。注意,并不是所有的图形设备都能渲染光栅图像。
ticks
A logical specifying if tick marks on colorbar should be visible.
在colorbar上指定标记的逻辑应该是可见的。
draw.ulim
A logical specifying if the upper limit tick marks should be visible.
一个逻辑指定如果上限的刻度标记应该是可见的。
draw.llim
A logical specifying if the lower limit tick marks should be visible.
一个逻辑指定如果下限刻度标记应该是可见的。
direction
A character string indicating the direction of the guide. One of "horizontal" or "vertical."
指示向导的方向的字符串。“水平的”或“垂直的”。
default.unit
A character string indicating unit for barwidth and barheight
.一个字符字符串指示单位的barwidth和barheight
reverse
logical. If TRUE the colorbar is reversed. By default, the highest value is on the top and the lowest value is on the bottom
合乎逻辑的。如果真,colorbar被颠倒了。默认情况下,最高的值在顶部,最低的值在底部
order
positive integer less that 99 that specifies the order of this guide among multiple guides. This controls the order in which multiple guides are displayed, not the contents of the guide itself. If 0 (default), the order is determined by a secret algorithm.
在多个指南中指定该指南顺序的99个正整数。这将控制显示多个向导的顺序,而不是向导本身的内容。如果0(默认),顺序由一个秘密算法决定。
... ignored.
Value
A guide object
Details
Guides can be specified in each scale_* or in guides guide="legend" in scale_* is syntactic sugar forguide=guide_legend() (e.g. scale_color_manual(guide = "legend")). As for how to specify the guide for each scale in more detail, ee guides
See also
Other guides: guide_legend, guides
Examples
df <- reshape2::melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p2 <- p1 + geom_point(aes(size = value))
# Basic form
p1 + scale_fill_continuous(guide = "colorbar")
# Control styles# bar size
p1 + guides(fill = guide_colorbar(barwidth = 0.5, barheight = 10))
# no label
p1 + guides(fill = guide_colorbar(label = FALSE))
# no tick marks
p1 + guides(fill = guide_colorbar(ticks = FALSE))
# label position
p1 + guides(fill = guide_colorbar(label.position = "left"))
# label theme
p1 + guides(fill = guide_colorbar(label.theme = element_text(colour = "blue", angle = 0)))
# small number of bins
p1 + guides(fill = guide_colorbar(nbin = 3))
# large number of bins
p1 + guides(fill = guide_colorbar(nbin = 100))
# make top- and bottom-most ticks invisible
p1 + scale_fill_continuous(limits = c(0,20), breaks = c(0, 5, 10, 15, 20), guide = guide_colorbar(nbin=100, draw.ulim = FALSE, draw.llim = FALSE))
# guides can be controlled independently
p2 + scale_fill_continuous(guide = "colorbar") + scale_size(guide = "legend")
p2 + guides(fill = "colorbar", size = "legend")
p2 + scale_fill_continuous(guide = guide_colorbar(direction = "horizontal")) + scale_size(guide = guide_legend(direction = "vertical"))
guide_legend
Legend guide
guides
Set guides for each scale
sec_axis dup_axis derive
Specify a secondary axis