0

I feel like many similar questions have been asked but I haven't found a solution to my problem yet in the related questions.

I am trying to change the colors on my map using spplot and the col.region command.

I have tried setting up a palette with the RColorBrewer package. I have tried using various values for the n: 5,6,7 (I am using 5 quantiles for my cuts) and even 1 to see if it would result in any observable change, but to no avail. I have also changed the choice of color several times but it also didn't bring any change. I have also tried setting up a color function the colorRampPalette function but also unsuccessfully.

The data I'm using can be downloaded here (sorry, I couldn't figure out how to upload it with the question) : http://www.data.drees.sante.gouv.fr/ReportFolders/reportFolders.aspx, by typing "APL" in search bar and taking the first excel file (2015); apologies can't manage to link it properly either)

My code is the following:

library(maptools) 
library(raster)
library(RColorBrewer)
library(readxl)
library(classInt)

apl15 <- read_excel("DATA USED")

france_com<- getData(name = "GADM",
                             country="FRA",
                             level=5) 
paca <- subset(fr_com,NAME_1=="Provence-Alpes-Côte d'Azur") 
apl15 <- data.frame(apl15) 
names(apl15) <- c("code_com","name_com","apl","apl_young","pop_com","dept","apl*pop") 

id_paca <- match(paca$NAME_5,apl15$name_com)  
key_paca<- apl15[id_paca,"apl"]  
paca$apl <- key_paca
apl.qt <- classIntervals(paca$apl,  
                         n=5, 
                         style="quantile")
br <- apl.qt$brks 
offs <- 0.0000001 
br[1] <- br[1] - offs 
br[length(br)] <- br[length(br)] + offs 

paca$apl_q <- cut(paca$apl,br)
display.brewer.all(type="seq")
my.palette <- brewer.pal(6, "OrRd")
spplot(paca,"apl_q", 
       col.region=my.palette,
       main="APL en PACA", cex.=.7) 

I expect this map but with colors corresponding to the palette I have selected.

my data mapped onto a region: my data mapped onto a region.

Thanks in advance for any help!

flafont11
  • 137
  • 7
  • Your code can not be used to reproduce the problem, for example what is `apl15 ` where does the function `classIntervals` come from? Please copy the code and try to run it in a new R session – DS_UNI May 31 '19 at 09:26
  • You're right thanks, I've edited the question. Still wasn't able to upload directly the data however. – flafont11 May 31 '19 at 10:37
  • Your issue is caused by a missing `s`, the parameter for choosing the color palette is `col.regions` – DS_UNI Jun 03 '19 at 07:57
  • that being said your code is still not reproducible as the excel you mentioned needs clean up and preparation (data types, missing values, ....) that is needed to run the rest of the code, after the cleanup I got a df with five columns while you were trying to assign 7 names to the df, and finally you used one time `france_com` and the other `fr_com`. – DS_UNI Jun 03 '19 at 07:58
  • I hope you accept my criticism, as I'm sure that you'll get a much quicker answer on your next question if you made sure that people can run your code as easily as possible. Meanwhile those two posts would help [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – DS_UNI Jun 03 '19 at 08:06
  • Yes of course, I realize now all the mistakes, not sure what I was thinking tbh. I have looked at the posts you linked and I'll do better next time. Thanks for the help! – flafont11 Jun 04 '19 at 09:16

0 Answers0