2

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 
jrshrenk
  • 121
  • 8
  • I presume you are running your script in batch mode. Then you should use `print()` to get your plots to display. – Andrie Nov 07 '13 at 19:33
  • I'm running the code interactively. I've tried wrapping in print() anyway to no effect. – jrshrenk Nov 07 '13 at 19:42
  • I have the same problem. Have you found a solution? – Ben Mar 17 '15 at 16:02
  • FWIW On OS X 10.10.2 & R 3.1.3 I get both an Atlanta .png and .pdf without issue – hrbrmstr Mar 18 '15 at 01:28
  • For me it also works: pdf: https://dl.dropboxusercontent.com/u/90010628/plot.pdf png: https://dl.dropboxusercontent.com/u/90010628/plot.png R version 3.1.1 (2014-07-10) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 [3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C [5] LC_TIME=Dutch_Netherlands.1252 – Huub Hoofs Mar 18 '15 at 15:52
  • I guess in your case Ben, its all updated? – Kvasir EnDevenir Mar 18 '15 at 23:13
  • @Ben are you running this over Remote Desktop (terminal services) by chance? – jrshrenk Mar 19 '15 at 15:49
  • @jrshrenk Yes (I think)... I'm on a Remote Desktop Citrix Server. – Ben Mar 19 '15 at 17:01
  • @Ben so that seems to be the one commonality here. I have no problem using the same R version and packages on my local machine. The map generates fine. On my server, over RDP (terminal services), the plot window generates a blank, white screen. Unfortunately, even if that has something to do with the problem, it doesn't get me to any kind of solution. Given the RDP link, this might not be a programming issue but more of a superuser type issue? Thoughts? – jrshrenk Mar 19 '15 at 20:10
  • @Ben Someone else appears to have had a [similar issue with base R](http://stackoverflow.com/questions/10728190/r-base-package-grid-does-not-produce-output). A bit unsatisfying as he was only able to observe the same behavior and come to the same conclusion that the plot has to be output to an alternate device. I wish I understood more about how using R over RDP would even make a difference. – jrshrenk Mar 19 '15 at 23:45
  • @jrshrenk Yes, and in fact when I install ggmap on my local desktop the map displays without any problems. Unfortunately I need to get it working inside my Citrix Remote Desktop. I've tried installing ggmap in both my User library and my System library and neither works. – Ben Mar 20 '15 at 00:49
  • @Ben I posted an answer below that worked for my situation. Can you test this as well? – jrshrenk Mar 21 '15 at 12:31
  • @Ben Any luck? I noticed on my laptop that sometimes the RDP client settings limit bit depth as well, so it has to be at 32 bit on both server and client. Hopefully you can get this working! – jrshrenk Mar 24 '15 at 14:54

2 Answers2

4

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.

Community
  • 1
  • 1
jrshrenk
  • 121
  • 8
0

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)
Kvasir EnDevenir
  • 907
  • 1
  • 10
  • 25
  • I updated my packages this morning (note that my original inquiry was back from Nov '13); still works when output via PDF or PNG but shows a blank plot within RStudio. ggmap_2.4 ggplot2_1.0.1 – jrshrenk Mar 19 '15 at 15:51
  • Rstudio viewer seems to be the challenge. Which version of Rstudio are you using? The code works perfectly here both in the R concole and in R studio with similar session info. I found this on graphical devices: http://stackoverflow.com/questions/23621012/display-and-save-the-plot-simultaneously-in-r-rstudio – Kvasir EnDevenir Mar 19 '15 at 16:31
  • I'm imagining some interaction between RDP and RStudio. I'm using 0.98.978 right now. Odd though since I have no problem with other plots--only this one where the raster map won't display (i.e., if I add more ggplot layers, those work fine--it's only the raster map that fails). – jrshrenk Mar 19 '15 at 20:15