我正在使用数据结果 ([https://drive.google.com/file/d/0B0zK9xcdOi1sQ1JaZFZYX1FQaUU/view?usp=sharing])
我要做的是使用maps包根据该州的标签值为美国地图的状态着色。
我正在尝试使用以下代码,但它不起作用。
library(choroplethr)
gtd <- read.csv("/Users/urAD_Jeff/Documents/Image analysis/result PNG/state.CSV")
statelabel<- ddply(gtd, .(y), "nrow")
colnames(statelabel) <- c("label", "value")
statelabel$label <- tolower(statelabel$label)
statelabel$label <- gsub(" (u.s. state)", "", statelabel$label, fixed=TRUE)
choroplethr(statlabel, lod="state")
想要的结果图像如下所示:
答案 0 :(得分:1)
这是最接近的(你缺少状态):
library(choroplethr)
library(choroplethrMaps)
library(plyr)
gtd <- read.csv("State.CSV")
statelabel <- gtd[,2:3]
colnames(statelabel) <- c("region", "value")
statelabel$region <- tolower(statelabel$region)
statelabel$region <- gsub(" (u.s. state)", "", statelabel$region, fixed=TRUE)
state_choropleth(statelabel)
# Warning in super$initialize(map.df, user.df) :
# Your data.frame contains the following regions which are not mappable:
# washington (state), unknown
# Warning in self$bind() :
# The following regions were missing and are being set to NA: north dakota,
# rhode island, south dakota, district of columbia