ggplot2脚注

发布于 2024-09-05 19:12:14 字数 583 浏览 3 评论 0原文

在使用 ggplot2 创建的绘图底部添加脚注的最佳方法是什么?我尝试使用所述逻辑的组合 此处 以及 ggplot2 annotate 函数。

p + annotate("text",label="Footnote",
  x=unit(1,"npc") - unit(2, "mm"),y=unit(2, "mm"),
  just=c("right", "bottom"),gp=gpar(cex= 0.7, col=grey(.5)))

但我收到错误

as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) 中的错误:无法将类 c("unit.arithmetic", "unit") 强制转换为 data.frame< /p>

What is the best way to add a footnote to the bottom of a plot created with ggplot2? I've tried using a combination of the logic noted here as well as the ggplot2 annotate function.

p + annotate("text",label="Footnote",
  x=unit(1,"npc") - unit(2, "mm"),y=unit(2, "mm"),
  just=c("right", "bottom"),gp=gpar(cex= 0.7, col=grey(.5)))

but I am getting the error

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class c("unit.arithmetic", "unit") into a data.frame

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

分開簡單 2024-09-12 19:12:14

使用labs(caption = "我的标题")

ggplot(mtcars, aes(mpg, wt, colour = cyl)) + 
  geom_point() + 
  labs(caption = "(Pauloo, et al. 2017)")

在此处输入图像描述

Use labs(caption = "my caption")

ggplot(mtcars, aes(mpg, wt, colour = cyl)) + 
  geom_point() + 
  labs(caption = "(Pauloo, et al. 2017)")

enter image description here

铜锣湾横着走 2024-09-12 19:12:14

我会使用类似的东西:

pdf("filename.pdf", width=10, height=6) # open an appropriate graphics device
print(p)
makeFootnote() # from webpage above (uses grid.text; ggplot2 is based on grid)
dev.off()

I would use something like that:

pdf("filename.pdf", width=10, height=6) # open an appropriate graphics device
print(p)
makeFootnote() # from webpage above (uses grid.text; ggplot2 is based on grid)
dev.off()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文