1

I'm trying to map the different denominations of the pencil in France. With the following code, I can achieve the map I want, the different colors representing the different items, and the score the rate of use of each item per department/region.

ggplot() + 
  geom_polygon(data = plotDatafr, aes(x=long, y = lat, group = group, fill=item, alpha=score), colour = NA) +
  scale_fill_manual(values = c("#009E73", "#F0E442", "#0072B2", "#D55E00"), name = "", na.value=NA) +
  coord_map()

enter image description here

I m now trying to find a way to smooth a little bit the color transitions between departments/regions. The map here gives an idea of what I m trying to achieve. My data is here. I'm aware of this post and I tried to follow this tutorial, but none of them is helpful for my problem.

EDIT

To create the map above, I calculated for each department the percentage of answers for a given item (5 different items) according to the total number of participants for each department (8272 participants in total). For each department, I then selected the item that received the max percentage, and plot these items on the map. I provided in this folder the raw data of the survey.

Description of the data

"id_part": the participant ; "PLZ": the zipcode of the participant's city ; "Lat"/"Long": long and lat values of the participant's city ; "NOM_DEPT": the department/region where the participant's city is located ; The rest of the columns indicate the answers (5 choices)

Shapefile is provided in the folder, I used this code to join the data (after having calculated and extracted the item with max percentage for each department) with the shapefile:

library(rgdal)
mapa <- readOGR(dsn="France",layer="DEPARTEMENT")
mapa <- spTransform(mapa, CRS("+proj=longlat +datum=WGS84"))
mapa@data$id <- rownames(mapa@data)
mapa@data   <- join(mapa@data, data, by="NOM_DEPT")
mapa.df     <- fortify(mapa)
mapa.df     <- join(mapa.df,mapa@data, by="id")
plotDatafr <- join(mapa.df, data)
Community
  • 1
  • 1
  • 1
    Your non-joined, original data source would be more helpful than the data that's been joined to the fortified map. I suspect your original data source is not going to be "dense" enough to make a decent 2D density plot w/o interpolation. Katz used [this data](http://www4.uwm.edu/FLL/linguistics/dialect/staticmaps/q_all.html) and, from what I can discern, you barely have 100 data points (hence the req for the actual, original data). – hrbrmstr Nov 20 '16 at 15:01
  • 3
    It looks like you're trying to make a heatmap, but in reality you're making a choropleth map, as you should. Smoothing the color transitions between boundaries will perhaps be a nice effect, but it will reduce the accuracy of your map. – yeedle Nov 20 '16 at 15:23
  • @hrbrmstr thanks a lot. I edited my question and provided the data. I have more than 8'000 data points before transformation – Mathieu Avanzi Nov 20 '16 at 16:01
  • @yeedle - yes, you're right. I edited the code and provied the non-transformed data – Mathieu Avanzi Nov 20 '16 at 17:04
  • 1
    for a choropleth map with multiple categories (dominance map), you could use tmap (https://cran.r-project.org/web/packages/tmap/index.html). if you have 4 categories, you can make 4 layers like this: `tm_shape(data1) + tm_fill(colorNA = transparent) + tm_shape(data2) + tm_fill(colorNA = transparent)`. in each layer, you only have values for the dominating category, all others are NA and NA is set to transparent. for each layer you have full control over colour and breaks etc. – Mario Nov 21 '16 at 13:00

0 Answers0