美国热图错误

问题描述 投票:0回答:1

我在这里收到错误:

library(ggmap)    
library(maptools)    
library(maps)    
library(ggplot2)    
library(fiftystater)    
library(reshape2)    

data("fifty_states")

map_stats <- read.csv(file.choose())    
ggplot(map_stats, aes(fill = statename, map_id = state)) +    
  geom_map(map = fifty_states) +    
  expand_limits(x = fifty_states$long, y = fifty_states$lat) +    
  coord_map() +    
  theme(legend.position = "bottom",    
        panel.background = element_blank()) 

我基本上跟随这个库中的这个例子:https://github.com/wmurphyrd/fiftystater

我正在尝试复制此图:https://i.imgur.com/DwIMgql.jpg 使用这个数据集:https://i.imgur.com/Aj03Jrm.jpg(它的所有五十个州,但你明白了)。目前我得到一个空白的情节窗格中的两个错误之一:

FUN(X [[i]],...)出错:找不到对象'state'

要么

不知道如何自动为data.frame类型的对象选择比例。违约持续。

错误:美学必须是长度1或与数据(54)相同:fill,map_id

r
1个回答
1
投票

我发现我必须将我的map_id = state重命名为我的表map_id = statename中的州列名称并且它有效

© www.soinside.com 2019 - 2024. All rights reserved.