4

I'm trying to create a choropleth map in R. I've merged my shapefiles and data files. I'm trying to create a palette for the different colours I want my data to display in on my choropleth. When I use the colorNumeric function it returns an error message.


library(leaflet)
library(rgdal)
library(tigris)
library(dplyr)

LAsMap <- readOGR(dsn = "C:/Users/LocalAuthorityShapefiles", 
        layer = "Local_Authority_Districts_December_2017_Generalised_Clipped_Boundaries_in_United_Kingdom_WGS84")

data <- read.csv(file = "C:/projects/N123.csv")

data_merged_map <- geo_join(LAsMap, data, "lad17cd", "lad17nm")


mypalette <- colorNumeric( palette="viridis", domain=data_merged_map$N456)

I expect the output to just run the code and create a palette in my workspace but instead the "Wasn't able to determine range of domain" error message appears.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
A.Wilcock
  • 41
  • 1
  • 5
  • What is in `data_merged_map$N456`? Would be interesting to see `dput(data_merged_map$N456)` if it's not too big. – asachet Sep 10 '19 at 14:49
  • It's 391 integers, I've just coded a variable for all local authorities as a binary for whether an attribute is present or not. But when I click on the data frame it says that the first ten entries are all "NA" - I'm not sure why this is the case! – A.Wilcock Sep 10 '19 at 14:57
  • It might be because the original data file has 321 data points, not 391. But even when I specify not to colour NA and to just leave it transparent, I get the same error message – A.Wilcock Sep 10 '19 at 14:58
  • Please try to make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Make sure `N456` is something which has a range: `NA`s may cause an issue but this could also be that `N456` is actually a string/character and not a numeric or integer as you'd expect. – asachet Sep 10 '19 at 15:22
  • Is this because some of your values may have `Inf` values? – oatmilkyway Mar 21 '20 at 00:25

1 Answers1

3

For me, this happened because I had -Inf values. Originally they were 0s, but I log10() transformed the vector, and that's what caused them to be -Inf for me.

Joe Flack
  • 866
  • 8
  • 14