我是一个R菜鸟,甚至是围绕着等等和映射的人。
我见过this thread以及线程链接到的其他人,但是无法解决这个问题。我试图在一个等值区域地图上绘制一些美国人口普查数据,尽管尝试了各种组合,我甚至不知道问题在哪里。
以下是简要代码:如果需要,可以提供更详细的代码。
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
注意:尽管不理解原因,我仍在使用强化:(
我得到的错误是:
Error in unit(x, default.units) : 'x' and 'units' must have length > 0