I'm creating a map in ggplot using a kml file of point data from google earth.
ggplot() +
geom_polygon(data = us, aes(x=long, y=lat, group=group), color = "black", fill = "white")+
geom_polygon(data = states, aes(x=long, y=lat, group=group), color = "black") +
geom_polygon(data = sw_counties, aes(x=long, y=lat, group=group), color = "black", fill = "white")
Before I add my point data, everything looks good with my map as far as the axes tick marks are concerned
The issue arises when I add my point data using geom_sf
. The axes tick marks now show what I believe are the degrees symbols and the cardinal direction associated with the coordinates.
ggplot() +
geom_polygon(data = us, aes(x=long, y=lat, group=group), color = "black", fill = "white")+
geom_polygon(data = states, aes(x=long, y=lat, group=group), color = "black") +
geom_polygon(data = sw_counties, aes(x=long, y=lat, group=group), color = "black", fill = "white")+
geom_sf(data = kml_points, aes(color = Name), size=3)
To the best of my knowledg this change occurs because the plot is drawing on my last layer, which is my google earth kml file, to create the axes. I realize this isn't a reproducible example, but is anyone aware of a workaround to remove the degrees and direction symbols from my axes tick marks? Maybe some way of specifying that the axes should be drawn from a previous map layer? Thank you!
You can override the default axis formatting by specifying labels = identity
in scale_*_continuous()
:
library(ggplot2)
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
ggplot(nc) +
geom_sf() +
scale_x_continuous(labels = identity) +
scale_y_continuous(labels = identity)
Created on 2024-03-01 with reprex v2.0.2