0

When executing the 'classIntervals' command I got the error while mapping data from Eurostat.

library(rgdal)
library(RColorBrewer)
library(sp)
library(GISTools)
library(classInt)
library(maptools)
library(SmarterPoland)
library(reshape)
library(reshape2)

# create a new empty object called 'temp' in which to store a zip file
# containing boundary data
temp <- tempfile(fileext = ".zip")
# now download the zip file from its location on the Eurostat website and
# put it into the temp object
  download.file("http://epp.eurostat.ec.europa.eu/cache/GISCO/geodatafiles/NUTS_2010_60M_SH.zip", temp)
# now unzip the boundary data
unzip(temp))
plot(EU_NUTS)

proj4string(EU_NUTS)

EU_NUTS <- spTransform(EU_NUTS, CRS("+proj=merc +a=6378137 +b=6378137  +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"))

plot(EU_NUTS)

EurostatTOC <- getEurostatTOC()

head(EurostatTOC)

data <- getEurostatRCV(kod = "lfst_r_lfu3rt")

unique(data$age)
unique(data$sex)
unique(data$time)

sub_data <- subset(data, (age == "Y20-64") & (sex == "T") & (time == "2012 "))

mapdata <- cast(data, geo ~ time + age + sex)

head(mapdata)

head(EU_NUTS@data)

EU_NUTS@data = data.frame(EU_NUTS@data, mapdata[match(EU_NUTS@data[, "NUTS_ID"],
                                              mapdata[, "geo"]), ])

my_colours <- brewer.pal(5, "BuGn")

breaks <- classIntervals(EU_NUTS@data$X2012._Y20.64_T, n = 5, style =   "fisher", unique = TRUE)$brks

## Error in classIntervals(EU_NUTS@data$X2012._Y20.64_T, n = 5, style = "fisher",  :  var is not numeric
  • What does str() or class() tell you about the column? Perhapse it, in fact, is not numeric. – Jeffrey Evans Aug 27 '18 at 1:50
  • After the unzip line (which has an extra )), which file are you reading into EU_NUTS? There's five shapefiles in that zip. – Spacedman Aug 27 '18 at 14:24
1

You've done this:

breaks <- classIntervals(EU_NUTS@data$X2012._Y20.64_T,
      n = 5, style =   "fisher", unique = TRUE)$brks

which is trying to get a column called "X2012._Y20.64_T". Does that exist?

> "X2012._Y20.64_T" %in% names(EU_NUTS)
[1] FALSE

No. There's something similar:

> "X2012_Y20.64_T" %in% names(EU_NUTS)
[1] TRUE

You've put an extra . in your column name. Remove that and it should work.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.