ggplot中annotate添加换行文本且左对齐
可以使用注释文本中的"\n"来添加换行文本。左对齐可以通过设置hjust参数为0实现。
例如,假设我们有以下数据和绘图代码:
library(ggplot2)
df <- data.frame(x = c(1, 2), y = c(3, 4))
ggplot(df, aes(x, y)) +
geom_point() +
annotate("text", x = 1, y = 4, label = "This is a long\nmultiline\ntext.", hjust = 0)
这将在x = 1,y = 4的位置添加一个注释文本,其中包含三行文本,并且左对齐。
原文地址: https://www.cveoy.top/t/topic/fy6H 著作权归作者所有。请勿转载和采集!