Ggmap Error when Plotting Lat and Long on United States Map

ggplot2
rstudio

#1

I'm currently having issues with using my ggmap package to plot any lat or long on the ggmap. I created a few tutorials a few months back with no issues and I'm starting to work on another and now it's not allowing any mapping. I receive multiple errors and I'm still running RStudio 3.4.3.

Code that I'm using

install.packages("dplyr") 
install.packages("ggmap")
install.packages("ggplot2") 
library(dplyr)
library(ggmap) 
library(ggplot2)

bw_map_us <- get_map(location = "United States", zoom = 4, color = "bw")

us_attacks$Latitude <- c(27.766279, 21.094318, 36.116203, 33.856892, 35.630066, 31.054487, 
                           44.572021, 40.298904, 33.040619, 42.165726, 32.806671, 37.769337, 
                           42.230171, 39.318523, 31.169546, 32.741646, 47.400902, 44.693947, 
                           41.597782, 41.680893, 39.063946)
us_attacks$Longitude <- c(-81.686783, -157.498337, -119.681564, -80.945007, -79.806419, 
                            -97.563461, -122.070938, 	-74.521011, -83.643074, -74.948051, 
                            -86.791130, -78.169968, -71.530106, -75.507141, -91.867805, 
                            -89.678696, -121.490494, -69.381927, 	-72.755371, -71.511780, 
                            -76.802101)


All is well until the run the below: code

ggmap(bw_map_us, extent = "device") + 
        geom_point(data = us_attacks, 
        aes(x = Longitude, y = Latitude, color = Total, size = Total)) + 
        scale_colour_gradient(low = "blue", high = "red")

I receive the below errors:

Theme element panel.border missing
Theme element axis.line.x.bottom missing
Theme element axis.ticks.x.bottom missing
Theme element axis.line.x.top missing
Theme element axis.ticks.x.top missing
Theme element axis.line.y.left missing
Theme element axis.ticks.y.left missing
Theme element axis.line.y.right missing
Theme element axis.ticks.y.right missing
Error in width_cm(guide$barwidth %||% theme$legend.key.width) :
Unknown input
In addition: Warning messages:
1: panel.margin is deprecated. Please use panel.spacing property instead
2: Removed 1 rows containing missing values (geom_point).

Any idea on this issue?


#2

It may be that ggmap breaks with ggplot2 3.0.0. See issue from GitHub repo:


#3

Thanks.

So this is an on-going issue? There's no response to that posts issue and it's 36 days old.

Is there a way to load an older version of ggplot2?

Cheers


#4

Yes! See here:


#5

I was actually looking into this but I am not 100% sure what the previous version is.


#6

Two places to figure this out (both linked from ggplot2’s CRAN page):

Or is there something else you’re trying to sort out?