OCHA-DAP / hdx-signals

HDX Signals
https://un-ocha-centre-for-humanitarian.gitbook.io/hdx-signals/
GNU General Public License v3.0
5 stars 0 forks source link

Remove warning generated from `geom_sf()` #83

Closed caldwellst closed 2 months ago

caldwellst commented 4 months ago

Somehow have maps not generate warnings when plotting longitude/latitude in geom_sf().

zackarno commented 4 months ago

will look into it more... just putting down a couple notes from my first glance:

Warning message:

Warning message:
In st_point_on_surface.sfc(sf::st_zm(x)) :
  st_point_on_surface may not give correct results for longitude/latitude data

Warning location

As indicated the warning message originates from sf::st_point_on_surface(), however in our context warning is only generated when labeling the cities insidegeom_cities() with geom_text_repel(). Interestingly no warning when plotting the point(s) themselves inside geom_cities()

ggrepel$geom_text_repel(
        data = sf_cities,
        mapping = gg$aes(
          label = name,
          geometry = geometry
        ),
        stat = "sf_coordinates",
        min.segment.length = Inf,
        family = "Source Sans 3",
        color = "black"
      )
zackarno commented 4 months ago

I think i found a work-around -- which is to add fun.geometry argument.

ggrepel$geom_text_repel(
        data = sf_cities,
        mapping = gg$aes(
          label = name,
          geometry = geometry
        ),
        stat = "sf_coordinates",
        fun.geometry = \(x) sf::st_centroid(x , of_largest_polygon = F),
        min.segment.length = Inf,
        family = "Source Sans 3",
        color = "black"
      )

Some points I don't fully understand yet:

  1. if of_large_polygon=T it works, but the point moves from default text_repel location. Not necessarily in a bad way
  2. running st_centroid() directly on the data input does not remove the warning message

I got the fun.geometry from: https://stackoverflow.com/questions/73623865/ggplot2-and-eurostat-row-removed-due-to-missing-values-geom-text-using-geom-s

So there might be some more interesting tidbits/clues there.

anyways will add the map testing PR

caldwellst commented 2 months ago

Closed by #75