Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Remove Degree and Cardinal Direction Symbols from ggplot Coordinate Axes

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

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

enter image description here

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!

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading