我相对使用R较新,尝试使用数据为美国各州创建地图以勾勒和着色特定区域。我尝试展示一个州及其县的黑色轮廓。在此基础上,我想创建厚重的红色边框以围绕一些县,并根据我拥有的一些数据填充某些县的颜色。
感谢您的帮助!以下是数据: https://www.dropbox.com/s/x8x2l50dvmg0lsb/QHP_IA_2017.csv?dl=0
基本上,我想要将这两个图像结合起来:
Then I would like to fill the map above like this
这是我迄今为止尝试完成此任务所编写的代码:
# Maping IA, plan 74406IA0010001
# Importing data
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(stringr)
library(plyr)
library(dplyr)
setwd("/Users/erinmay/Desktop/WL_RA/marketplace2/data")
county <- map_data("county")
plan <- read.csv("IA_2017.csv")
# Using subset
iowa <- subset(county, region=="iowa") #county point files for iowa
# Merging in map data
countyplan <- merge(x=iowa, y=plan, by=c("region","subregion"), all.x=TRUE)
countyplan <- countyplan[order(countyplan$chosen_plan),]
# Creating map
final <- ggplot(data=countyplan) +
geom_path(aes(x=long,y=lat,group=RatingArea),colour='black') +
geom_polygon(aes(x=long,y=lat,group=group,fill=chosen_plan)) +
coord_map() + coord_fixed(1.3)
ggsave(final,height=6,width=10,unit='in',file='iowa.pdf')
感谢您的帮助!以下是数据: https://www.dropbox.com/s/x8x2l50dvmg0lsb/QHP_IA_2017.csv?dl=0