2

我正在使用 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 
4

2 回答 2

4

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

在远程桌面会话中,所有环境变量,包括决定颜色深度的显示变量,都由 RCP-Tcp 连接设置决定。例如,用户可以在通过慢速连接时降低颜色深度。不同的设置是每像素 15 位、16 位、24 位或 32 位。要提高远程桌面颜色深度:

在 Windows 服务器上,从附件菜单启动远程桌面会话主机配置。在连接下,右键单击 RDP-Tcp 并选择属性。在 Client Settings 选项卡上,取消选中 LimitMaximum Color Depth 或将其设置为每像素 32 位。

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

于 2015-03-21T12:29:56.140 回答
0

jrshrenk 似乎有一段时间没有更新 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)
于 2015-03-18T23:07:46.467 回答