Question

I am using the ggmap library in R to produce a map of the Atlanta area. When running the code, I'm able to get points plotted on the map as well as other layers, but am not able to get the map itself to print in any graphics device other than PDF. I suspect a configuration issue as I'm able to use this code on a different computer without issue, but two other machines simply display blank plots.

Here is a scaled down version of the code. I am assuming that my blank plots won't be reproducible, but I'm hoping to get some guidance on where the configuration problem might be.

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()

Session Info:

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   

And capabilities:

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 
Was it helpful?

Solution

The problem has to do with the server limiting the bit depth that gets passed through the connection. Oracle documents the problem and solution on their site:

In a Remote Desktop session, all environment variables, including display variables determining Color Depth, are determined by the RCP-Tcp connection settings. For example, users can reduce the Color Depth when connecting over a slow connection. The different settings are 15 bits, 16 bits, 24 bits, or 32 bits per pixel. To raise the Remote Desktop color depth:

On the Windows server, launch Remote Desktop Session Host Configuration from the Accessories menu. Under Connections, right click on RDP-Tcp and select Properties. On the Client Settings tab either uncheck LimitMaximum Color Depth or set it to 32 bits per pixel.

Upon unchecking the "Limit Maximum Color Depth" check box and reconnecting to the server, the raster map backgrounds now show up as expected. Note that they also provide option 2 which is to output to an alternate device.

OTHER TIPS

It seems jrshrenk haven't updated R and the packages in a while. Although in theory your versions of R, ggmap, png and ggplot2 seems sufficient:

    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

I would just try to update R and the packages to see if it solves the issue:

#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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top