小编J. *_*Lee的帖子

如何使用 ggplot2 在 y 轴截距(y 轴)上添加一个点

我有一个散点图,其中 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)

plot r data-visualization scatter-plot ggplot2

5
推荐指数
1
解决办法
755
查看次数

标签 统计

data-visualization ×1

ggplot2 ×1

plot ×1

r ×1

scatter-plot ×1