我正在尝试使用我的 x 轴应用自定义缩放ggplot2
and scales::trans_new()
。但是,当我这样做时,一些轴标签丢失了。有人可以帮我弄清楚为什么吗?
Setup:
library(tidyverse)
# the data
ds <- tibble(
myx = c(1, .5, .1, .01, .001, 0),
myy = 1:6
)
# the custom transformation
forth_root_trans_rev <- scales::trans_new(
name = "sign_fourth_root_rev",
transform = function (x) { - abs(x)^(1/4) },
inverse = function (x) { x^4 }
)
Plot 1:
当我尝试绘制这个标签时x = 0
迷路。
# plot - missing x-label at `0`
ggplot(ds, aes(x = myx, y = myy)) +
geom_line() +
geom_point() +
scale_x_continuous(
trans = forth_root_trans_rev,
breaks = sort(unique(ds$myx)),
)
Plot 2
当我在图表两侧添加一些空间时,更多的 x 标签会丢失。
# plot - missing x-labels below 0.5
ggplot(ds, aes(x = myx, y = myy)) +
geom_line() +
geom_point() +
scale_x_continuous(
trans = forth_root_trans_rev,
breaks = sort(unique(ds$myx)),
expand = expand_scale(mult = c(.1, .6))
)
我认为这与这个老问题有关:https://github.com/tidyverse/ggplot2/issues/980 https://github.com/tidyverse/ggplot2/issues/980。尽管如此,我不知道如何应用此转换并保留所有 x 标签。
我哪里错了?