我正在使用R中的GGMAP库来制作亚特兰大地区的地图。运行代码时,我能够在地图上以及其他层上绘制的点,但无法在PDF以外的任何图形设备中打印地图本身。我怀疑配置问题,因为我可以在没有问题的情况下在另一台计算机上使用此代码,但是另外两台机器只是显示空白图。

这是代码的缩放版本。我假设我的空白块不可再现,但是我希望对配置问题的位置获得一些指导。

library('ggplot2')
library('ggmap')
library('mapproj')

# ggmapTemp.png gets saved to the working directory correctly
atlanta <- get_map(location=c(lon=-84.26039,
                              lat=33.8751),
                   zoom=9,maptype='roadmap')

atlantaMap <- ggmap(atlanta, extent = 'device', legend = 'topleft')

# this produces a blank plot from both RStudio as well as R
atlantaMap

# this produces the actual map correctly
pdf("plot.pdf")
atlantaMap
dev.off()

# this produces a png file with only a white background
png("plot.png")
atlantaMap
dev.off()

会话信息:

R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mapproj_1.2-1    ggmap_2.3        ggplot2_0.9.3.1  maps_2.3-6       maptools_0.8-27 
 [6] sp_1.0-14        car_2.0-19       reshape2_1.2.2   plyr_1.8         Revobase_6.2.0  
[11] RevoMods_6.2.0   RevoScaleR_6.2.0 lattice_0.20-13  rpart_4.1-0     

loaded via a namespace (and not attached):
 [1] codetools_0.2-8     colorspace_1.2-4    dichromat_2.0-0     digest_0.6.3        foreach_1.4.0      
 [6] foreign_0.8-52      grid_2.15.3         gtable_0.1.2        iterators_1.0.6     labeling_0.2       
[11] MASS_7.3-23         munsell_0.4.2       nnet_7.3-5          png_0.1-6           proto_0.3-10       
[16] RColorBrewer_1.0-5  RgoogleMaps_1.2.0.5 rjson_0.2.13        RJSONIO_1.0-3       scales_0.2.3       
[21] stringr_0.6.2       tools_2.15.3   

和功能:

jpeg      png     tiff    tcltk      X11     aqua http/ftp  sockets   libxml     fifo   cledit 
TRUE     TRUE     TRUE     TRUE    FALSE    FALSE     TRUE     TRUE     TRUE    FALSE     TRUE 
iconv      NLS  profmem    cairo 
TRUE     TRUE     TRUE     TRUE 
有帮助吗?

解决方案

问题与服务器限制了通过连接传递的位深度有关。 Oracle 记录问题和解决方案 在他们的网站上:

在远程桌面会话中,所有环境变量(包括确定颜色深度的显示变量)均由RCP-TCP连接设置确定。例如,用户可以在缓慢的连接上连接时降低颜色深度。不同的设置为15位,16位,24位或每个像素32位。提高远程桌面颜色深度:

在Windows Server上,从附件菜单启动远程桌面会话主机配置。在连接下,右键单击RDP-TCP并选择属性。在“客户端设置”选项卡上,请限制最大颜色深度或将其设置为每个像素32位。

在取消选中“限制最大颜色深度”复选框并重新连接到服务器后,现在按预期显示了栅格地图背景。请注意,它们还提供了选项2,该选项将输出到备用设备。

其他提示

似乎有一段时间没有更新R和包装。尽管从理论上讲,您的R,GGMAP,PNG和GGPLOT2的版本似乎足够:

    Package: ggmap
    Version: 2.4
    Depends: R (>= 2.14.0), ggplot2 (>= 0.9.2)
    Imports: proto, scales, RgoogleMaps, png, plyr, reshape2, grid, rjson,
            mapproj, jpeg, geosphere, digest
    Suggests: MASS, stringr
        License: GPL-2
        NeedsCompilation: no

    Package: png
    Version: 0.1-7
    Depends: R (>= 2.9.0)
    License: GPL-2 | GPL-3
    NeedsCompilation: yes

我只会尝试更新R和软件包,以查看是否解决了问题:

#Save your current packages but not the base ones:
savepackages <- rownames(installed.packages(priority='NA')) 
write(savepackages, file="listpackages.txt")

#Check for Updates of R
library(installr)
check.for.updates.R(notify_user = TRUE, use_GUI = TRUE,
                    page_with_download_url = "http://cran.rstudio.com/bin/windows/base/",
                    pat = "R-[0-9.]+-win")

#Download and Install New Version
install.R(page_with_download_url = "http://cran.rstudio.com/bin/windows/base/",
          pat = "R-[0-9.]+-win.exe", to_checkMD5sums = TRUE,
          keep_install_file = TRUE, download_dir = tempdir(), silent = FALSE)

#Then reinstall packages 
pkg.ls <- read.table("listpackages.txt")
install.packages(pkg.ls)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top