在绘图区域外添加文本 [英] Add text outside plot area

查看:83
本文介绍了在绘图区域外添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例代码

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

如何像在使用上图所示的示例中那样向x轴添加任意文本,然后在上面写上任意单词"

How if it is possible to add arbitrary text to the x axis like in this example made using the plot above and then I wrote on it "arbitrary words"

推荐答案

我不确定您要尝试执行的操作,这可能会或可能不会很好地推广.

I'm not entirely sure what you're trying to do so this may or may not generalise well.

也就是说,一种可能性是将annotatecoord_cartesian(clip = "off")一起使用以允许绘图区域之外的文本.

That said, one possibility is to use annotate with coord_cartesian(clip = "off") to allow text outside the plot area.

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")

这篇关于在绘图区域外添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆