0

I'm an R noob, and even noob-er around choropleths and mapping.

I've seen this thread and others that the thread links to, but just cannot get around this problem. I am trying to map some USA census data on a choropleth map, and I don't even know where the problem is despite trying various combinations.

Here's the brief code: can provide more detailed code if required.

code <- c(1:2, 4:6, 8:13, 15:42, 44:51, 53:56, 72)
statename <- c("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", "Puerto Rico")

statelist <- data.frame(code, statename)

populDataNew <- merge(x = populData, y = statelist, by.x = "State", by.y = "code")
incomestate <- ddply(populData, c("Income", "statename"), summarise, incomebystate = sum(Income))
edu <- select(populDataNew, c(statename, EduAttainment), na.rm=TRUE)
edusum <- ddply(edu, c("statename"), summarise, edubystate = mean(EduAttainment))

states_map <-map_data("state")
states_map <- fortify(states_map, region = "statename")

m <- ggplot(edusum, aes(map_id = statename)) + geom_map(aes(fill = edubystate), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat)
m

Note: I'm using fortify despite not understanding why :(

The error I am getting is:

Error in unit(x, default.units) : 'x' and 'units' must have length > 0
Community
  • 1
  • 1
Deepa
  • 3
  • 5

0 Answers0