简体   繁体   English

使用plot_usmap包在R中创建地图图

[英]Creating a map plot in R using plot_usmap package

I have a dataset containing different states, zip codes, and claim counts each in separate columns. 我有一个包含不同状态,邮政编码和索赔计数的数据集,它们分别在不同的列中。 I am trying to create a plot to show the total claim count according to zip codes for the state of MA. 我正在尝试创建一个图,以根据MA州的邮政编码显示总索赔计数。

Dataset: 数据集: 在此处输入图片说明

I used this to filter by MA: 我用它来过滤MA:

MA_medicare <- medicare %>%
  filter(medicare$NPPES.Provider.State == "MA")

I then used this to set the fips code for plot_usmap: 然后,我用它来设置plot_usmap的fips代码:

MA_medicare$NPPES.Provider.State <- fips(MA_medicare$NPPES.Provider.State)
setnames(MA_medicare, old=c("NPPES.Provider.State"), new=c("fips"))

And last tried to graph (not sure why this doesn't work): 最后尝试绘制图形(不确定为什么这不起作用):

plot_usmap(data = MA_medicare, values= c("Total.Claim.Count", "NPPES.Provider.Zip.Code"), include = c("MA")) + scale_fill_continuous(low= "white", high= "red") + theme(legend.position = "right") 

Error: Aesthetics must be either length 1 or the same as the data (4350838): fill 错误:美学必须为长度1或与数据相同(4350838):填充

I'm the developer of usmap . 我是usmap的开发人员。 plot_usmap only accepts one column of values for plotting so you're probably looking for the following: plot_usmap仅接受一列值进行绘图,因此您可能正在寻找以下内容:

plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))

However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). 但是,您的数据是按邮政编码分类的,当前usmap不支持邮政编码地图(仅州和县级地图)。 It uses the FIPS column to assign colors to states/counties on the map. 它使用FIPS列为地图上的州/县分配颜色。 Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color. 由于您是按州定义FIPS代码的,因此只用一种纯色填充马萨诸塞州的整个州。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM