[R-sig-Geo] Saving plot as PDF from functions levelplot and gplot from rasterVis package

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Mar 23 09:22:02 CET 2012


No:

require(lattice)
pdf("x.pdf")
xyplot(1~1)
dev.off()

produces the pdf with the plot I expected.

Calling print() on trellis objects is needed when this is not the
default action, for instance in a loop or a { } block where the plot is
not the return value. I guess that this is the same for gplot.

On 03/23/2012 02:14 AM, Stephen Sefick wrote:
> ggplot and lattice require that you print the output.
> 
> pdf("mpgplot.pdf")
> a <- gplot(maparaster) + geom_tile(aes(fill = value))
> print(a)
> dev.off()
> 
> HTH
> 
> Stephen
> 
> On Thu 22 Mar 2012 11:11:56 AM CDT, Manuel Spínola wrote:
>> Thank you very much Paul,
>>
>> My problem now is with the output from gplot (rasterVis, ggplot2), the
>> problem with levelplot was solved by the suggestion from Oscar Perpiñán.
>>
>> The map is at:
>> https://docs.google.com/open?id=0B5pDw_grXll8a21uQzB5ZlRULWl3ZWZxdU44b2Nvdw
>>
>>
>> mapa = read.asc("Ectophylla_alba.asc" ,gz=FALSE)
>> image(mapa)
>>
>> write.asc(mapa, "mapar")
>>
>> maparaster = raster("mapar.asc")
>>
>> pdf("mpgplot.pdf")
>> gplot(maparaster) + geom_tile(aes(fill = value))
>> dev.off()
>>
>> Also, using ggsave (ggplot2) did not solve the problem.
>>
>> Best,
>>
>> Manuel
>>
>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> -- 
> Stephen Sefick
> **************************************************
> Auburn University
> Biological Sciences
> 331 Funchess Hall
> Auburn, Alabama
> 36849
> **************************************************
> sas0025 at auburn.edu
> http://www.auburn.edu/~sas0025
> **************************************************
> 
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make
> us feel like gods.  We are mammals, and have not exhausted the annoying
> little problems of being mammals.
> 
>                                -K. Mullis
> 
> "A big computer, a complex algorithm and a long time does not equal
> science."
> 
>                              -Robert Gentleman
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list