francesca Pancotto
2016-Jun-02  09:37 UTC
[R] Map of Italy data filled at the level of the province
Dear Users
I am very new to the use of ggplot. I am supposed to make a plot of 
Italian provinces in which I have to fill the color of some provinces 
with the values of a variable(I do not provide the data because it is irrelevant
which data to use).
Right now I explored the function map in maps package thanks to which I managed
to plot
the map of Italy with provinces borders and select only those provinces
contained in the
vector nomi(which is just a list of character elements with the names of the
provinces which are
just like counties in the US).
map("italy",col=1:20, regions=nomi)
The problem is to fill the provinces level with the values of a variable that is
the variable of interest:
I found a series of examples based on US data extracted from very hard to get
databases.
Can anyone provide an easy example where to start from?
Thanks in advance
Francesca
----------------------------------
Francesca Pancotto
Professore Associato di Politica Economica
Universit? degli Studi di Modena e Reggio Emilia
Palazzo Dossetti - Viale Allegri, 9 - 42121 Reggio Emilia
Office: +39 0522 523264
Web: https://sites.google.com/site/francescapancotto/
----------------------------------
	[[alternative HTML version deleted]]
This should help you get started:
  library(maptools)
  library(ggplot2)
  library(ggalt)
  library(ggthemes)
  library(tibble)
  library(viridis)
  # get italy region map
  italy_map <- map_data("italy")
  # your data will need to have these region names
  print(unique(italy_map$region))
  # we'll simulate some data for this
  set.seed(1492)
  choro_dat <- data_frame(region=unique(italy_map$region),
                          value=sample(100, length(region)))
  # we'll use this in a bit
  italy_proj <- "+proj=aea +lat_1=38.15040684902542
+lat_2=44.925490198742295 +lon_0=12.7880859375"
  gg <- ggplot()
  # lay down the base layer
  gg <- gg + geom_map(data=italy_map, map=italy_map,
                      aes(long, lat, map_id=region),
                      color="#b2b2b2", size=0.1, fill=NA)
  # fill in the regions with the data
  gg <- gg + geom_map(data=choro_dat, map=italy_map,
                      aes(fill=value, map_id=region),
                      color="#b2b2b2", size=0.1)
  # great color palette (use a better legend title)
  gg <- gg + scale_fill_viridis(name="Scale title")
  # decent map projection for italy choropleth
  gg <- gg + coord_proj(italy_proj)
  # good base theme for most maps
  gg <- gg + theme_map()
  # move the legend
  gg <- gg + theme(legend.position=c(0.95, 0.3))
  gg
This uses a continuous color palette for the region fill. You may want
to consider binning data and using a discrete fill (IMO that's usually
a better choice for most choropleths).
-Bob
On Thu, Jun 2, 2016 at 5:37 AM, francesca Pancotto
<francesca.pancotto at gmail.com> wrote:> Dear Users
> I am very new to the use of ggplot. I am supposed to make a plot of
> Italian provinces in which I have to fill the color of some provinces
> with the values of a variable(I do not provide the data because it is
irrelevant which data to use).
>
> Right now I explored the function map in maps package thanks to which I
managed to plot
> the map of Italy with provinces borders and select only those provinces
contained in the
> vector nomi(which is just a list of character elements with the names of
the provinces which are
> just like counties in the US).
>
> map("italy",col=1:20, regions=nomi)
>
> The problem is to fill the provinces level with the values of a variable
that is the variable of interest:
> I found a series of examples based on US data extracted from very hard to
get databases.
>
> Can anyone provide an easy example where to start from?
>
> Thanks in advance
> Francesca
>
> ----------------------------------
> Francesca Pancotto
> Professore Associato di Politica Economica
> Universit? degli Studi di Modena e Reggio Emilia
> Palazzo Dossetti - Viale Allegri, 9 - 42121 Reggio Emilia
> Office: +39 0522 523264
> Web: https://sites.google.com/site/francescapancotto/
> ----------------------------------
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.