我有一个散点图,其中 y 轴缩放比例在某个点发生变化以绘制具有某些极值的数据。我正在尝试在 y 轴上添加某种视觉提示,指示缩放在该点发生变化。
这是一个情节的例子
library(scales)
library(ggplot2)
set.seed(104)
ggdata <- data.frame('x' = rep('a',100),
'y' = c(runif(90, 0, 20), runif(10, 90, 100)))
transformation <- trans_new(
"my_transformation",
transform = function(x) ifelse(x <= 30, x / 5, (x - 30) / 20 + 30 / 5),
inverse = function(x) ifelse(x <= 30 / 5, x * 5, (x - 30 / 5) * 20 + 30)
)
ggplot(data = ggdata) +
geom_jitter(aes(x = x, y = y)) +
scale_y_continuous(trans = transformation, breaks …Run Code Online (Sandbox Code Playgroud)