我只是想将绘图保存到文件中,看起来它使整个系列的 R 设备都失败了:
getgrob = function(x, y) {
require(grid)
x = 1:10
y = rnorm(10)
plotvp = plotViewport(c(5, 5, 3, 3), name='plotvp')
datavp = dataViewport(x, y, name='datavp')
datapts = pointsGrob(
x, y, pch=20,
size=unit(2.3, 'mm'),
name='datapts',
gp=gpar(col='black')
)
xaxis = xaxisGrob()
yaxis = yaxisGrob()
xlab = textGrob('X Label', y=unit(-3, 'lines'), name='xlab')
ylab = textGrob('Y Label', x=unit(-3, 'lines'), rot=90, name='ylab')
plotbox = rectGrob()
dataplot = gTree(children=gList(datapts,
xaxis, yaxis,
xlab, ylab,
plotbox),
vp=datavp, name='dataplot')
wholeplot = gTree(children=gList(dataplot),
vp=plotvp, name='wholeplot')
wholeplot
}
pdf('/tmp/a.pdf')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
png('/tmp/a.png')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
jpeg('/tmp/a.jpg')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
tiff('/tmp/a.tiff')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
bmp('/tmp/a.bmp')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
svg('/tmp/a.svg')
mygrob = getgrob(1:10, rnorm(10))
grid.draw(mygrob)
dev.off()
我得到的只是一个带有轴和刻度的空白区域:
但是 pdf 设备仍然可以工作。我在这里错过了什么吗?
这是版本信息:
R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)