这是一种提供一些功能的方法,尽管它有点小技巧。好处是它提供了一个易于扫描的绘图历史缩略图数组。
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 然后是axis、lines、更多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)
它再次更新。