每个比例的指南可以使用 guide 参数设置 scale-by-scale ,或者使用 guides() 一起设置。
参数
- ...
 - 
name-guide 秤对列表。指南可以是字符串(即 "colorbar" 或 "legend"),也可以是对指定其他参数的指南函数(即
guide_colourbar()或guide_legend())的调用。 
也可以看看
其他指南:guide_bins()、guide_colourbar()、guide_coloursteps()、guide_legend()
例子
# \donttest{
# ggplot object
dat <- data.frame(x = 1:5, y = 1:5, p = 1:5, q = factor(1:5),
 r = factor(1:5))
p <-
  ggplot(dat, aes(x, y, colour = p, size = q, shape = r)) +
  geom_point()
# without guide specification
p
#> Warning: Using size for a discrete variable is not advised.
# Show colorbar guide for colour.
# All these examples below have a same effect.
p + guides(colour = "colorbar", size = "legend", shape = "legend")
#> Warning: Using size for a discrete variable is not advised.
p + guides(colour = guide_colorbar(), size = guide_legend(),
  shape = guide_legend())
#> Warning: Using size for a discrete variable is not advised.
p +
 scale_colour_continuous(guide = "colorbar") +
 scale_size_discrete(guide = "legend") +
 scale_shape(guide = "legend")
#> Warning: Using size for a discrete variable is not advised.
 # Remove some guides
 p + guides(colour = "none")
#> Warning: Using size for a discrete variable is not advised.
 p + guides(colour = "colorbar",size = "none")
#> Warning: Using size for a discrete variable is not advised.
# Guides are integrated where possible
p +
  guides(
    colour = guide_legend("title"),
    size = guide_legend("title"),
    shape = guide_legend("title")
 )
#> Warning: Using size for a discrete variable is not advised.
# same as
g <- guide_legend("title")
p + guides(colour = g, size = g, shape = g)
#> Warning: Using size for a discrete variable is not advised.
p + theme(legend.position = "bottom")
#> Warning: Using size for a discrete variable is not advised.
# position of guides
# Set order for multiple guides
ggplot(mpg, aes(displ, cty)) +
  geom_point(aes(size = hwy, colour = cyl, shape = drv)) +
  guides(
   colour = guide_colourbar(order = 1),
   shape = guide_legend(order = 2),
   size = guide_legend(order = 3)
 )
# }
相关用法
- R ggplot2 guide_legend 图例指南
 - R ggplot2 guide_bins Guide_legend 的分箱版本
 - R ggplot2 guide_axis 轴导轨
 - R ggplot2 guide_coloursteps 离散颜色条指南
 - R ggplot2 guide_colourbar 连续色条指南
 - 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等大神的英文原创作品 Set guides for each scale。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
