我正在尝试使用 ggplot2
中的 grid.text
将文本框添加到我的绘图中。该图本身运行良好,但当我添加 grid.text
命令时,出现错误“不知道如何将 o 添加到图中”。如果使用 last_plot()
,我仍然会收到错误消息,但字母会显示在图表上 - 但不会与绘图的其余部分一起保存。数据集和命令如下:
foldchange order
1.583591249 1c
1.973012368 1c
1.339505031 1c
0.776845711 2c
1.004515622 2c
1.225864907 2c
13.27371225 3c
7.599476289 3c
10.74132453 3c
3.347536996 4c
4.286202467 4c
3.612756449 4c
17.40825874 5c
20.61039144 5c
ggplot(test, aes(order, foldchange)) + geom_point() #this part works fine
+ grid.text(label="a", x=.18, y=.9) + #this part gives me the error
提前致谢!
最佳答案
那是因为 grid.text 是网格的一部分,而不是 ggplot。此外,grid.text 只绘制它不会将其添加到 ggplot 对象的底层结构的内容。 您正在寻找注释。
ggplot(test, aes(order, foldchange)) + geom_point() +
annotate(geom = "text", label="a", x=.18, y=.9)
这个情节是用:
ggplot(test, aes(order, foldchange)) + geom_point() +
annotate(geom = "text", label="a", x=5, y=.9)
因为 x = 0.18
不会显示。
关于r - 将 grid.text 添加到 ggplot 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12115701/