Hi Barry,

Just a small addition based on your example.
## fortify(columbus,region="id") ## did not work for me
# but this works:
library(spdep)
example(columbus)
columbus@data$AREA
fco <- fortify(columbus, region= "AREA")
ggplot(columbus@data) +
  geom_map(map=fco, aes(map_id=AREA,fill=AREA)) +
expand_limits(x=c(5,12),y=c(10,15))

# indeed ggplot is quite fussy about it's spatial food
Cheers,
Jan

R> sessionInfo()R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C
LC_COLLATE=C
 [5] LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C
LC_NAME=C
 [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C
LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
 [1] spdep_0.5-46    coda_0.15-2     deldir_0.0-19   nlme_3.1-104
MASS_7.3-19
 [6] Matrix_1.0-6    boot_1.3-5      rgeos_0.2-7     plyr_1.7.1
stringr_0.6
[11] ggplot2_0.9.1   gpclib_1.5-1    maptools_0.8-16 lattice_0.20-6
sp_0.9-99
[16] foreign_0.8-50

loaded via a namespace (and not attached):
 [1] RColorBrewer_1.0-5 colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2
 [5] grid_2.15.1        labeling_0.1       memoise_0.1        munsell_0.3
 [9] proto_0.3-9.2      reshape2_1.2.1     scales_0.2.1       tools_2.15.1

R>


On Sun, Jul 22, 2012 at 10:38 PM, Barry Rowlingson <
b.rowlingson@lancaster.ac.uk> wrote:

> 2012/7/22 Manuel Spínola <mspinola10@gmail.com>:
> > Dear list members,
> >
> > Sorry for cross-posting.
> >
> > I asked this question to a ggplot2 forum, but I would like to have other
> > suggestions from this list.
> >
> > How can I plot a shapefile with the new function geom_map from ggplot2?
>
>  Well, R is an object-oriented system, so in an ideal world you'd just
> pass it anything that geom_map is capable of doing whatever it is that
> geom_map needs to do on an object as its 'map' parameter.
>
>  Sadly, geom_map, like most ggplot2 functions, is quite fussy about
> its food. It likes its map objects fortified, much like corn flakes or
> low-fat milk. So you have to fortify it. Literally:
>
>  myspdf=readOGR(".","myshapes")
>  fort = fortify(myspdf)
>
>  And you might also have to specify an id. The help(geom_map) isn't
> too clear. Then you have to figure out how to get ggplot() and
> geom_map() and anything else to talk to each other. At this point you
> may consider just doing:
>
>  plot(myspdf, col=somefunction(myspdf$Value))
>
> where somefunction() maps your values to colours, like a colourPalette
> function. Or even:
>
>  spplot(myspdf, "Value")
>
>  I tried to do some maps with geom_map for my spatial data workshop
> but I hit this documentation problem and a couple of bugs - if I'd had
> more time I would have worked it out, but as it stood it darn near
> broke me.
>
> Okay, here's how to plot the regions of the columbus dataset from the
> spdep package (see example(columbus)) shaded by the AREA within the
> given limnits:
>
>  ggplot(columbus@data)+geom_map(
>        map=fortify(columbus,region="id"),
>        aes(map_id=id,fill=AREA)) +
>        expand_limits(x=c(5,12),y=c(10,15))
>
>
> Barry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

