'Add points to usmap with ggplot in r

I was able to create a US map with this tutorial. When I tried to add additional points to it they all ended up in South Dakota, no matter what I input for data.

library(ggplot2)
library(usmap)
testData <- data.frame(LATITUDE = 20.31557, LONGITUDE = -102.42547)
p <- plot_usmap( regions = "state") 
p + geom_point(data = testData, aes(x = LONGITUDE, y = LATITUDE), color = "red")


Solution 1:[1]

As of usmap 0.5.0, a new function exists called usmap_transform which transforms a data.frame to match the projection used by usmap.

Here is an example similar to the data you provided:

library(usmap)
library(ggplot2)

# Lat/Lon of Sioux Falls, SD
test_data <- data.frame(lon = -96.70, lat = 43.55)

transformed_data <- usmap_transform(test_data)

plot_usmap("states") + 
  geom_point(data = transformed_data, 
             aes(x = x, y = y), 
             color = "red",
             size = 3)

Plot showing a single red point on a US map, where Sioux Falls, SD is located

There is also a new vignette called Advanced Mapping which shows this in more detail.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1