[R-sig-Geo] gplot error in rasterVis

Oscar Perpiñán Lamigueiro oscar.perpinan at gmail.com
Thu May 30 15:52:09 CEST 2013


Hi,

With the current definition of gplot you have to add the layers you need
to plot (that's why you get the error "No layers to plot"). Take a look
at the example of the help page. With your example:

gplot(r) + geom_tile(aes(fill=value)) + coord_equal()

On the other hand, the warning when you use gplot is because both
latticeExtra and ggplot2 define the function layer. If ggplot2 is loaded
after rasterVis, the layer definition from latticeExtra becomes
masked. If you plan to use latticeExtra (for example, to add layers over
the result of a levelplot call) you should load ggplot2 before
rasterVis.

Best,

Oscar.

Natalie Wagenbrenner <nwagenbrenner at gmail.com> writes:

> I'm trying to use gplot() in rasterVis to plot a RasterLayer object
> using ggplot2
> graphics, but I keep getting an error.  Here is a reproducible
> example:
>
> library(raster)
> library(rasterVis)
>
> r <- raster(ncol=10, nrow=10)
> values(r) <- 1:ncell(r)
> gplot(r)
>
> The following `from` values were not present in `x`: col, color, pch,
> cex, lty, lwd, srt, adj, bg, fg, min, max
> Error: No layers in plot
>
> I see the following warning when I load rasterVis:
>
> Loading required package: ggplot2
>
> Attaching package: ‘ggplot2’
>
> The following object(s) are masked from ‘package:latticeExtra’:
>
>     layer
>
> Perhaps this is part of the problem? Or I am misunderstanding the
> gplot() methods somehow? Thanks for any suggestions.
>
> Natalie
>
> Session info:
>
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C
> LC_TIME=en_CA.UTF-8
>  [4] LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8
> LC_MESSAGES=en_CA.UTF-8
>  [7] LC_PAPER=C                 LC_NAME=C
> LC_ADDRESS=C
> [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8
> LC_IDENTIFICATION=C
>
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets
> methods   base
>
> other attached packages:
>  [1] ggmap_2.3           RgoogleMaps_1.2.0.3 png_0.1-4
> maps_2.3-2          rasterVis_0.20-07
>  [6] hexbin_1.26.2       latticeExtra_0.6-24 RColorBrewer_1.0-5
> lattice_0.20-0      ggplot2_0.9.3.1
> [11] rgdal_0.8-9         raster_2.1-25       sp_1.0-9
> ncdf_1.6.6          vimcom_0.9-8
> [16] setwidth_1.0-3      colorout_1.0-0
>
> loaded via a namespace (and not attached):
>  [1] colorspace_1.2-2 dichromat_2.0-0  digest_0.6.3     gtable_0.1.2
>   labeling_0.1     mapproj_1.2-1
>  [7] MASS_7.3-16      munsell_0.4      plyr_1.8         proto_0.3-10
>   reshape2_1.2.2   rjson_0.2.12
> [13] scales_0.2.3     stringr_0.6.2    zoo_1.7-9
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan



More information about the R-sig-Geo mailing list