0
votes

I'm getting errors here:

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()) 

I'm basically following along with this example in this library: https://github.com/wmurphyrd/fiftystater

I'm trying to replicate this graph: https://i.imgur.com/DwIMgql.jpg
using this data set: https://i.imgur.com/Aj03Jrm.jpg (its all fifty states but you get the idea). Currently I'm getting a blank plot pane one of two errors:

Error in FUN(X[[i]], ...) : object 'state' not found

or

Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

Error: Aesthetics must be either length 1 or the same as the data (54): fill, map_id

1
Can you please post the data, either uploaded or using dput so we can avoid retyping the data? I think your problem is that map_id needs to be shared across both the fiftystater data and the plot data, as noted if you look at ?geom_map. At least by default, the id for each state in fiftystater::fifty_states is not called state but id, and in your example picture it is called statename. - Calum You

1 Answers

1
votes

I found i had to rename my map_id = state to the name of the state column in my table map_id = statename and it worked