示例代码
library(ggplot2)
ggplot(mtcars, aes(mpg, cyl, color = vs)) + geom_line()
如果可以向x轴添加任意文本,如上图所示,然后我在上面写上“任意单词”,该如何处理呢?
发布于 2019-02-20 07:14:37
我不能完全确定您想要做的是什么,这可能会也可能不会很好地概括。
也就是说,一种可能性是结合使用annotate
和coord_cartesian(clip = "off")
来允许绘图区域之外的文本。
ggplot(mtcars, aes(mpg, cyl, color = vs)) +
geom_line() +
annotate("text", x = 12.5, y = 3.5, label = "Arbitrary text") +
coord_cartesian(ylim = c(4, 8), clip = "off")
发布于 2019-02-20 07:14:50
您可以在ggplot2
中使用tag
(请参见?ggplot2::labs
)并指定它在theme
中的位置
library(ggplot2)
ggplot(mtcars, aes(mpg, cyl, color = vs)) +
geom_line() +
labs(tag = "arbitrary words") +
theme(plot.tag.position = c(0.15, 0.02))
https://stackoverflow.com/questions/54776142
复制相似问题