如果我创建一个带有par(mfrow=...)
的多绘图窗口,是否可以将数据发送到特定的绘图(即“左下角的那个”)或者绘图总是必然是连续的? R有没有这样的包?
对于那些感兴趣的人来说,出现这个问题的原因是R是一个单线程应用程序,并不适合实时可视化。我有多个实时数据流从外部源进入R,异步生成数据(因此数据流并不总是以相同的顺序)。这导致R每次更新时都会围绕数据可视化图的顺序翻转。
答案 0 :(得分:11)
您可以使用split.screen()
:
par(bg = "white") # erase.screen() will appear not to work
# if the background color is transparent
# (as it is by default on most devices).
split.screen(c(2,1)) # split display into two screens
split.screen(c(1,3), screen = 2) # now split the bottom half into 3
screen(1) # prepare screen 1 for output
plot(10:1)
screen(4) # prepare screen 4 for output
plot(10:1)
答案 1 :(得分:3)
看看help(layout)
。这允许您指定尺寸,位置和尺寸。
一旦绘制,我不认为你只是部分地重新绘制。但是你可以使用dev.set()
等来在不同的“绘图设备”(即窗口)之间切换;见help(dev.list)
。
答案 2 :(得分:2)
请注意,此处建议的答案是使用split.screen()。它可能有效,但根据split.screen帮助文件:“使用这些函数的推荐方法是在选择和绘制另一个屏幕之前,将绘图和所有添加(即点和线)完全绘制到基本绘图中与返回到添加到现有绘图的屏幕相关联的行为是不可预测的,并且可能导致不易看到的问题。“
在回答我的问题时,使用par(mfg)选项有一个更有用的解决方案:
答案 3 :(得分:1)
另一种选择是实现一点GUI,例如使用RGtk2
或RTclTk
。
我通常会为想要实时更改的图表执行此操作,但效果很好。
例如,使用RGtk2
和cairoDevice
,你可以做一些事情(我假设你有一个Glade界面)
# Helper function to get a widget from the Glade interface
getWidget <- function(name)
{
return (interface$getWidget(name))
}
interface <- gladeXMLNew("interface.glade", root="mainWindow")
# Our cairo devices (to draw graphics).
# plot1, plot2, and plot3 are GtkDrawingArea widgets
asCairoDevice(getWidget("plot1"))
# dev.cur() will give the device number of the last device we created
# You'll use this to switch device when you draw in different plots
# Storing the device number is important because you may have other
# devices open from other unrelated plots
# (so never assume they'll just start from 1 and be sequential!!!)
plot1.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot2"))
plot2.dev <- as.integer(dev.cur())
asCairoDevice(getWidget("plot3"))
plot3.dev <- as.integer(dev.cur())
# To draw in a specific plot you just do
dev.set(plot2.dev)
plot(....)
这有许多其他优点,例如能够轻松地将图形放置在您想要的位置(使用Glade界面设计器)并且可以通过特定按钮进行用户交互(例如,您可能有“暂停采集”按钮)