1

I am plotting some data on a shapefile using R and choropleth in packageGISTools I would like to modify my code below in order to assign custom breaks.

Using the World Borders Dataset, download from: http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip

library(GISTools)
library(rgdal)

shape_file <- readOGR(dsn ="/home/hamid/TM_WORLD_BORDERS_SIMPL-0.3",
                      layer = "TM_WORLD_BORDERS_SIMPL-0.3")

shades <- auto.shading(shape_file@data$POP2005, cutter = quantileCuts, 
                       n=5, cols = brewer.pal(5, "Blues"))
choropleth(shape_file, shape_file@data$POP2005,
           shading = shades)                      
choro.legend(70.00000, 32.50000, shades)

Can anyone help please?

UPDATE

No errors in the code I have posted. What I would like to do is to use custom cuts instead of quantile cuts. I have trie the following:

cuts= c(0.1, 0.2, 0.3, 0.4, 0.6)
shades <- shading(shape_file@data$POP2005, breaks = cuts)
choropleth(shape_file, shape_file@data$POP2005, shading = shades) 

which give the following error:

Error in findInterval(v, shading$breaks) : 
vec' must be sorted non-decreasingly`

Note that the values for the breaks are specific to my case which is not using the same data on the example.

  • Can you specify the problem? any error message? – dof1985 Jul 28 '16 at 12:53
  • I update the post. – Caserio Jul 28 '16 at 12:59
  • I have used your code on my machine and I get no error. Can you make a simple reproducible example of your error? – dof1985 Jul 28 '16 at 13:22
  • Can you post the result of shades$breaks ? – dof1985 Jul 28 '16 at 13:32
  • 1
    I can't really help you without a reproducible error. The code you provided above, works. Basically the error say that you must use breaks that are sorted non-decreasingly. Namely cuts <- c(1, 2, 3) is good and cuts <- c(3, 2, 1) is no good. – dof1985 Jul 28 '16 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.