【问题标题】:How can I view all plots in Rstudio at once?如何一次查看 Rstudio 中的所有绘图?
【发布时间】:2018-12-16 16:48:29
【问题描述】:

我想滚动浏览我在 RStuido 中创建的所有图。在处理了一天的数据之后,我想看看我可以使用哪些图。所以我想快速滚动浏览我的情节缩略图。

在现有的绘图查看器中等待单击左键需要一段时间,因为必须重新绘制每个绘图查看器,然后才能再次单击左键。我想一次看到它们并选择一个进行更仔细的检查。是否有我缺少的包或设置能够做到这一点?

【问题讨论】:

  • 解决您的问题的几个选项:(1)制作布局并在面板中查看所有图; (2) 制作一个包含所有图的 PDF,例如,每个图都在一页中。
  • 这听起来像是对 RStudio 的功能请求 - 目前我认为没有任何方法可以从 R 代码控制 RStudio 图形窗口,例如无法复制“以前”的情节R中的箭头按钮(如果我错了,请纠正我)。试试community.rstudio.com
  • 加布里埃尔,这两个答案中的任何一个都足以满足您的需求吗?好奇你是否发现了更好的东西。

标签: r rstudio


【解决方案1】:

这是一种提供一些功能的方法,尽管它有点小技巧。好处是它提供了一个易于扫描的绘图历史缩略图数组。

rmote 包提供了远程查看绘图的功能。也就是说,如果我 ssh 到远程主机并且不想尝试进行 X 转发,我可以转发一个简单的端口并在网页上查看我的所有图形。 (注意:这在本地工作得很好,不需要 ssh-ing。)

devtools::install_github("cloudyr/rmote")

library(rmote)
start_rmote()
# To stop the server, run servr::daemon_stop("140656622179224") or restart your R session
# Serving the directory /tmp/RtmpgOIU3c/rmote_server at http://127.0.0.1:4321

此时,打开指向该 URL 的浏览器窗口,http://127.0.0.1:4321

这个答案的其余大部分只是演示基本图形ggplot2,以及不工作的gridExtra ...如果你尝试的话,再加上修复。绘图代码无关紧要,但您在浏览器窗口中看到的结果在这里:

基础图形需要更多的工作,当你完成“构建”情节时使用plot_done()。这是必需的(我认为),因为使用基本图形通常需要几个函数调用(plot 然后是axislines、更多points 等)。即使你只想做一个单调用情节并随它去,你仍然需要做plot_done()

plot(mpg~disp, data=mtcars)
# serving graphics through rmote
# when finished with plot commands, call plot_done()
abline(a=10, b=1/10)
plot_done()
# making thumbnail

一旦您运行最后一个函数,网页就会自动更新为全尺寸图像和缩略图列表。我会继续...

ggplot2 图形“按原样”工作,不需要plot_done()

library(ggplot2)
qplot(carat, price, data = diamonds)
qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.05)
qplot(carat, data = diamonds, geom = "histogram")

不幸的是,我无法立即让 grid.arrange 绘图工作。

通常,当您使用rmote 时,没有图形设备:

dev.list()
# NULL

但是,当我尝试grid.arrange 时:

library(gridExtra)
plot1 <- qplot(carat, data = diamonds, geom = "histogram", binwidth = 1)
plot2 <- qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.1)
plot3 <- qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.05)
grid.arrange(plot1, plot2, plot3, ncol=3)

什么都没有显示,但现在我们启动了一个新设备:

dev.list()
# pdf
#   2

此时,现在正常的绘图不起作用:

qplot(carat, data = diamonds, geom = "histogram", binwidth = 1)
# - not sending to rmote because another graphics device has been opened...
# - sending to the open graphics device instead...
# - to send to rmote, close all active graphics devices using graphics.off()
dev.list()
# pdf
#   2
graphics.off()
qplot(carat, data = diamonds, geom = "histogram", binwidth = 1)

它再次更新。

【讨论】:

    【解决方案2】:

    根据您的设置,一种选择是将您的工作组织到 R Markdown 文件中。

    它有一个显示所有图表的选项,只需在 RStudio 的Tools -&gt; Global Options ... -&gt; R Markdown 菜单下设置它。然后,您将在 RStudio 的编辑器中预览所有图表,您可以单击 Show in New Window 进行进一步调查:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多