r - 在绘图区域外添加文本

标签 r ggplot2

示例代码

library(ggplot2)
ggplot(mtcars, aes(mpg, cyl, color = vs)) + geom_line()

如果可以像使用上面的图制作的这个示例中那样将任意文本添加到 x 轴,然后我在上面写上“任意文字”

enter image description here

最佳答案

我不完全确定你想要做什么,所以这可能会也可能不会很好地概括。

也就是说,一种可能性是使用 annotatecoord_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")

enter image description here

关于r - 在绘图区域外添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54776142/

相关文章:

r - ggplot2 geom_bar 填充美学没有改变

r - 如何扩展分位数回归线 geom_quantile 以在 ggplot 中进行预测?

r - 在dplyr中,setdiff和anti_join之间的内在区别是什么?

r - tsoutliers 依赖问题 : dependency KFKSDS has non-zero exit status?

r - 散点图和最佳拟合线 - 两组

r - 如何使用条件语句为条形图着色

r - 例如,当图例位置为底部时,如何将图例标题放在标签的顶部?

r - 有没有办法计算 R 中多个数据帧中每个单元格的标准差?

r - 错误: nrow(x) == n is not TRUE when using Train in Caret

r - 如何在 ggplot 命令中激活两个不同的 scale_fill_manual