此注释添加了间距递减的对数刻度线。这些刻度线可能只对以 10 为基数的情况有意义。
用法
annotation_logticks(
  base = 10,
  sides = "bl",
  outside = FALSE,
  scaled = TRUE,
  short = unit(0.1, "cm"),
  mid = unit(0.2, "cm"),
  long = unit(0.3, "cm"),
  colour = "black",
  size = 0.5,
  linetype = 1,
  alpha = 1,
  color = NULL,
  ...
)
参数
- base
 - 
日志的基数(默认10)
 - sides
 - 
控制对数刻度出现在图的哪一侧的字符串。它可以设置为包含任何
"trbl"的字符串,用于顶部、右侧、底部和左侧。 - outside
 - 
控制是否将日志刻度移动到绘图区域之外的逻辑。默认关闭(
FALSE)。您还需要使用coord_cartesian(clip = "off")。请参阅示例。 - scaled
 - 
数据已经log-scaled了吗?当数据已使用
log10()转换或使用scale_y_log10()时,这应该是TRUE(默认)。使用coord_trans(y = "log10")时应为FALSE。 - short
 - 
指定短刻度线长度的
grid::unit()对象 - mid
 - 
指定中间刻度线长度的
grid::unit()对象。以 10 为基数,这些是 "5" 刻度。 - long
 - 
指定长刻度线长度的
grid::unit()对象。以 10 为基数,这些是"1"(或"10")刻度。 - colour
 - 
刻度线的颜色。
 - size
 - 
刻度线的厚度,以毫米为单位。
 - linetype
 - 
刻度线的线型(
solid、dashed等) - alpha
 - 
刻度线的透明度。
 - color
 - 
colour的别名。 - ...
 - 
传递到层的其他参数
 
也可以看看
scale_y_continuous() 、 scale_y_log10() 用于对数刻度转换。
coord_trans() 用于日志坐标转换。
例子
# Make a log-log plot (without log ticks)
a <- ggplot(msleep, aes(bodywt, brainwt)) +
 geom_point(na.rm = TRUE) +
 scale_x_log10(
   breaks = scales::trans_breaks("log10", function(x) 10^x),
   labels = scales::trans_format("log10", scales::math_format(10^.x))
 ) +
 scale_y_log10(
   breaks = scales::trans_breaks("log10", function(x) 10^x),
   labels = scales::trans_format("log10", scales::math_format(10^.x))
 ) +
 theme_bw()
a + annotation_logticks()                # Default: log ticks on bottom and left
a + annotation_logticks(sides = "lr")    # Log ticks for y, on left and right
a + annotation_logticks(sides = "trbl")  # All four sides
a + annotation_logticks(sides = "lr", outside = TRUE) +
 coord_cartesian(clip = "off")  # Ticks outside plot
# Hide the minor grid lines because they don't align with the ticks
a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank())
# Another way to get the same results as 'a' above: log-transform the data before
# plotting it. Also hide the minor grid lines.
b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) +
 geom_point(na.rm = TRUE) +
 scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) +
 scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) +
 theme_bw() + theme(panel.grid.minor = element_blank())
b + annotation_logticks()
# Using a coordinate transform requires scaled = FALSE
t <- ggplot(msleep, aes(bodywt, brainwt)) +
  geom_point() +
  coord_trans(x = "log10", y = "log10") +
  theme_bw()
t + annotation_logticks(scaled = FALSE)
#> Warning: Removed 27 rows containing missing values (`geom_point()`).
# Change the length of the ticks
a + annotation_logticks(
  short = unit(.5,"mm"),
  mid = unit(3,"mm"),
  long = unit(4,"mm")
)
相关用法
- R ggplot2 annotation_custom 注释:自定义grob
 - R ggplot2 annotation_map 注释:Map
 - R ggplot2 annotation_raster 注释:高性能矩形平铺
 - R ggplot2 annotate 创建注释层
 - R ggplot2 aes_eval 控制审美评价
 - R ggplot2 aes 构建美学映射
 - R ggplot2 as_labeller 强制贴标机函数
 - R ggplot2 vars 引用分面变量
 - R ggplot2 position_stack 将重叠的对象堆叠在一起
 - 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 stat_ellipse 计算法行数据椭圆
 - R ggplot2 resolution 计算数值向量的“分辨率”
 - R ggplot2 geom_boxplot 盒须图(Tukey 风格)
 - R ggplot2 lims 设置规模限制
 - R ggplot2 geom_hex 二维箱计数的六边形热图
 - R ggplot2 scale_gradient 渐变色阶
 - R ggplot2 scale_shape 形状比例,又称字形
 - R ggplot2 geom_bar 条形图
 - R ggplot2 draw_key 图例的关键字形
 - R ggplot2 label_bquote 带有数学表达式的标签
 
注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Annotation: log tick marks。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
