coord_flip()
中使用 clip = "off"
与 geom_text
结合使用,这将允许绘制图形元素超出图形面板。显然,您需要调整 x
和 y
来使用此手动方法获得所需的输出。library(ggplot2)
p <- ggplot(iris,
aes(x = Species,
y = Sepal.Width)) +
geom_boxplot() +
labs(x = NULL,
y = "Sepal Width") +
coord_flip(clip = "off") + # add clip = off here
theme(axis.title.y = element_text(angle = 0, hjust = 0))
p +
# add axis title here
geom_text(
x = 3.5,
y = 1.85,
inherit.aes = FALSE,
label = "Species",
check_overlap = TRUE,
hjust = 1,
fontface = 'bold',
size = 5
) +
theme(plot.margin = unit(c(1, 1, 1, 2), "lines"))
这段内容是由 reprex package (v0.2.1)创建于2018年10月27日。