有对数小刻度的图是怎么画出来的呢?

原始数据的分布
msleep %>%
ggplot(aes(bodywt, brainwt))+
geom_point(na.rm = T)+theme_bw()

对数转换
msleep %>%
ggplot(aes(bodywt, brainwt)) +
geom_point(na.rm = T)+
scale_x_log10()+
scale_y_log10()+theme_bw()

msleep %>%
ggplot(aes(log10(bodywt), log10(brainwt)))+
geom_point(na.rm = T)+theme_bw()

规范刻度值
a <- ggplot(msleep, aes(bodywt, brainwt, color = vore)) +
geom_point(na.rm = TRUE, size = 3, alpha = .8) +
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

下级
添加小刻度
a + annotation_logticks() # Default: log ticks on bottom and left

a + annotation_logticks(sides = "trbl")

a + annotation_logticks(sides = "trbl", outside = TRUE)

a + annotation_logticks(sides = "trbl", outside = TRUE) +
coord_cartesian(clip = "off")

# a + annotation_logticks(sides = "trbl", outside = TRUE) +
# coord_cartesian(clip = "on")
刻度长度修改
# Change the length of the ticks
a + annotation_logticks(
short = unit(.5,"mm"),
mid = unit(3,"mm"),
long = unit(4,"mm")
)
