R 在ggplot中用箭头注释hline

R 在ggplot中用箭头注释hline,r,ggplot2,R,Ggplot2,我制作了一个这样的箱线图,在其中我用“test”注释hline 库(ggplot2) df试试这个: library(ggplot2) library(wrapr) df <- data.frame(x = rnorm(100)) df %.>% ggplot(data = ., aes(y = x)) + geom_boxplot() + geom_hline(yintercept = 0.0) + geom_text(aes( x = -.3,

我制作了一个这样的箱线图,在其中我用“test”注释hline

库(ggplot2)
df试试这个:

library(ggplot2)
library(wrapr)

df <- data.frame(x = rnorm(100))

df %.>%
  ggplot(data = ., aes(y = x)) +
  geom_boxplot() +
  geom_hline(yintercept = 0.0) +
  geom_text(aes(
      x = -.3,
      y = min(.$x),
      label = 'test'
    ),
    check_overlap = TRUE
  ) +
  geom_segment(aes(
      x = -.3,
      xend = -.2,
      y = min(.$x) * .95,
      yend = 0
    ),
    size = 1,
    arrow = arrow()
  )
库(ggplot2)
图书馆(wrapr)
df%
ggplot(数据=,aes(y=x))+
geom_箱线图()+
geom_hline(yintercept=0.0)+
geom_文本(aes)(
x=-0.3,
y=最小值(.$x),
标签='test'
),
检查重叠是否为真
) +
geom_段(aes)(
x=-0.3,
xend=-.2,
y=最小值(.$x)*.95,
yend=0
),
尺寸=1,
arrow=arrow()
)

如果您想使用折弯线,请使用
geom_曲线
而不是
geom_段
,并使用
曲率
参数调整曲率。

是否回答了您的问题?您的建议基本上是手动定义箭头。@spore234 Sry。我没有读你问题的最后一行。见不恰当的回答。
library(ggplot2)
library(wrapr)

df <- data.frame(x = rnorm(100))

df %.>%
  ggplot(data = ., aes(y = x)) +
  geom_boxplot() +
  geom_hline(yintercept = 0.0) +
  geom_text(aes(
      x = -.3,
      y = min(.$x),
      label = 'test'
    ),
    check_overlap = TRUE
  ) +
  geom_segment(aes(
      x = -.3,
      xend = -.2,
      y = min(.$x) * .95,
      yend = 0
    ),
    size = 1,
    arrow = arrow()
  )