相关疑难解决方法(0)

自定义缩放轴后,ggplot2缺少标签

我正在尝试使用ggplot2和自定义X轴缩放比例scales::trans_new()。但是,当我这样做时,某些轴标签会丢失。有人可以帮我找出原因吗?

设定:

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 }
)
Run Code Online (Sandbox Code Playgroud)

情节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, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 axis-labels

7
推荐指数
1
解决办法
84
查看次数

标签 统计

axis-labels ×1

ggplot2 ×1

r ×1