实现所需结果的一个简单选项是使用辅助轴技巧添加注释,即添加辅助x轴并通过轴文本添加注释。如果你需要一些额外的造型,你可以使用例如。
ggtext
.
注意:我掉了
coord_flip
而是切换
x
和
y
.
library(ggplot2)
library(ggtext)
ggplot(data = forest1, aes(y = var1, x = HR1, xmin = lower1, xmax = upper1)) +
geom_pointrange() +
geom_vline(xintercept = c(.4, 1), lty = 2) +
scale_x_continuous(
sec.axis = dup_axis(
breaks = c(.325, .6, 1.075),
labels = c("Words", "Words", "**More Words**")
),
limits = c(0.3, 1.1)
) +
theme_bw() +
labs(x = NULL, y = "HR") +
theme(
axis.text.x.top = ggtext::element_markdown(size = 12),
axis.ticks.x.top = element_blank()
)