R基本包格不产生输出基本、包格不

2023-09-11 09:04:32 作者:我就是我,不一样的烟火

我在Windows Server 2008 R2的Amazon EC2实例上运行64位R 2.15.0。 电网不产生输出。例如,下面的code应产生的装置中的窗口的单个对角线:

I am running 64-bit R 2.15.0 on a Windows Server 2008 R2 Amazon EC2 instance. grid does not produce output. For example, the following code should produce a single diagonal line in a device window:

grid.newpage()
l <- linesGrob()
grid.draw(l)

但是,我什么也看不见。是否有一个标志或选项,我应该使用Windows Server 2008 R2上,使电网输出?

I, however, see nothing. Is there a flag or option I should be using on Windows Server 2008 R2 to enable grid output?

编辑:另一种可重复的例子,在我家(的Windows 7 64位)和工作电脑(Windows XP中)作品:

Another reproducible example that works on my home (Windows 7 x64) and work PCs (Windows XP):

library(grid)
library(png)

img.path <- system.file("img", "Rlogo.png", package="png")
bg <- readPNG(img.path)
background <- rasterGrob(unclass(bg))

grid.draw(background)

这是预期的输出,因为看到我的工作电脑上(调整大小以适应下):

This is the expected output, as seen on my work PC (resized to fit below):

推荐答案

研究不正确地在窗口的设备通过远程桌面连接产生的光栅图像。如果光栅图像是必需的,积必须是输出到另一装置。

R does not produce raster images correctly in the window device over Remote Desktop Connection. If a raster image is required, the plot must be output to another device.

library(ggplot2)
library(grid)
library(maps)
library(mapproj)
library(png)
library(RgoogleMaps)

counties <- map_data("county", region="virginia")
states <- map_data("state")

tmp <- tempfile(fileext=".png")
bg <- GetMap.bbox(range(counties$long), range(counties$lat), destfile=tmp, 
     maptype="satellite", format="png32")
background <- readPNG(tmp)
background <- rasterGrob(unclass(background))

p <- ggplot(counties, aes(long, lat)) +
   coord_map(xlim=c(bg$BBOX$ll[2], bg$BBOX$ur[2]), 
             ylim=c(bg$BBOX$ll[1], bg$BBOX$ur[1])) +
   geom_path(aes(group=group), color="darkgrey") +
   geom_path(data=states, aes(group=group), color="white", size=1) +
   opts(axis.line=theme_blank(),
        axis.text.x=theme_blank(),
        axis.text.y=theme_blank(),
        axis.ticks=theme_blank(),
        axis.title.x=theme_blank(),
        axis.title.y=theme_blank(),
        axis.ticks.length=unit(0, "lines"),
        axis.ticks.margin=unit(0, "lines"),
        panel.border=theme_blank(),
        panel.background=function(...)background,
        panel.grid.major=theme_blank(),
        panel.grid.minor=theme_blank(),
        panel.margin=unit(0, "lines"),
        legend.position="none",
        legend.title=theme_blank(),
        legend.background=theme_blank(),
        plot.margin=unit(0*c(-1.5, -1.5, -1.5, -1.5), "lines"))

pdf("plot.pdf", height=7, width=7)
p
dev.off()

我发现了 PDF之间书写绘图命令() dev.off()产生空白文件。存储在一个对象的情节,并调用它会工作。

I have found that writing plotting commands between the pdf() and dev.off() produces blank files. Storing the plot in an object and calling it will work.