1

This is what my data looks like: Data

I want to draw a map for state of Hawaii, where each latitude and longitude is a marker of different color based on the category in dummy, and then a legend based on that dummy column value.

The furthest I have gone is using this attempt, where cleanData is the name of my dataframe.

test_data <- data.frame(lon = cleanData$Longitude, lat = cleanData$Latitude)
transformed_data <- usmap_transform(test_data)

plot_usmap(include = c("HI")) + 
  geom_point(data = transformed_data, 
             aes(x = x, y = y), 
             color = "red",
             size = 1)
stefan
  • 90,330
  • 6
  • 25
  • 51
  • 2
    It looks like you're new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput()` and any libraries you are using. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Aug 18 '22 at 02:51

1 Answers1

0

You could achieve your desired result by adding your dummy column to your dataset and mapping it on the color aes:

library(usmap)
library(ggplot2)

test_data <- data.frame(
  lon = c(-157.8822, -157.7993),
  lat = c(21.33517, 21.39912),
  dummy = c("L2", "L2_DC")
)

transformed_data <- usmap_transform(test_data)
#> Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
#> prefer_proj): Discarded datum unknown in Proj4 definition

plot_usmap(include = "HI") +
  geom_point(
    data = transformed_data,
    aes(x = x, y = y, color = dummy),
    size = 3
  )

stefan
  • 90,330
  • 6
  • 25
  • 51