user3357059
user3357059

Reputation: 1192

Overlay a shape file on over a ggmap

I'm having problems to overlay a shape file over a ggmap map.

The shape file is fine when I run it by itself, see pic below.

library(ggmap)
library(grid)

la <- get_map(location="Los Angeles County", zoom=9)

# get base map layer
gg <- ggmap(la)

 library(broom)

  LaCountyTracts <- CalifCensusTracts %>% 
   tidy(region = "GEOID") %>%
   filter(grepl("06037", id))

 ggplot(LaCountyTracts, aes(long, lat, group = group) ) +
      geom_polygon(   fill = "grey40", 
           colour = "grey90", alpha = .7, size = .05) +
      coord_map() +
      theme_minimal() 

enter image description here

The code below produced the deformed shape layer when the ggmap and the shape file are combined.

 gg + geom_polygon(data=LaCountyTracts,aes(x=long, y=lat,group=group),
                      colour = "grey90", alpha = .7, size = .05)

enter image description here

Upvotes: 1

Views: 703

Answers (1)

user3357059
user3357059

Reputation: 1192

changed the line from

la <- get_map(location="Los Angeles County", zoom=9)

to

la <- get_map(location="Los Angeles County", zoom = 8)

and that fixed the problem

Upvotes: 0

Related Questions