AustralianAntarcticDivision / SOmap

Southern Ocean round maps
https://australianantarcticdivision.github.io/SOmap/
24 stars 6 forks source link

Wanted: point labels for SOmap_auto #94

Closed jspmccain closed 3 years ago

jspmccain commented 3 years ago

I'm wondering how to add point labels to the plot after using SOmap_auto().

I've tried using the text() function similar to how this might be done in base R, but I can't seem to get it to work. I wonder if it there is a simple solution that I'm just not seeing?

For example:

example_df <- data.frame(long = runif(10, 130, 200), lat = runif(10, -85, -60), station = c("A", "B", "C"))
SOmap_auto(example_df$long, example_df$lat)

I would also want there to be corresponding labels (A etc.).

Thank you!

raymondben commented 3 years ago

Hi Scott - text will work, you just need to make sure you are working with data that's in the same projection as the map:

example_df <- data.frame(long = runif(10, 130, 200), lat = runif(10, -85, -60), station = letters[1:10])
SOmap_auto(example_df$long, example_df$lat)

The plotted map is in projected coordinates. To get our long-lat data into the same projection:

exdf_p <- SOproj(example_df)

which is a SpatialPointsDataFrame. And finally:

text(exdf_p, labels = example_df$station)
mdsumner commented 3 years ago

SOtext() a good idea though, there'd be a good case for extending each of the base plot calls for the "projection handling" for the current plot from longlat data.

I'd like to revisit this, but it would be a package that SOmap imports, something that does this projection-context stuff - so no promises or timeline but its' certainly on the radar

jspmccain commented 3 years ago

Thank you!