Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_labelsf() not recognizing aesthetics #74

Open
Pecners opened this issue Mar 2, 2022 · 5 comments
Open

geom_labelsf() not recognizing aesthetics #74

Pecners opened this issue Mar 2, 2022 · 5 comments

Comments

@Pecners
Copy link

Pecners commented Mar 2, 2022

First of all, thank you for this fantastic package! The issue I'm having is that geom_labelsf() doesn't seem to be passing on aesthetic arguments on to geom_labelpath() as the documentation indicates.

For instance, here's an example of geom_labelsf() not recognizing the fill or text_only arguments.

library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.1.2
#> Warning: package 'tidyr' was built under R version 4.1.2
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(geomtextpath)
#> Warning: package 'geomtextpath' was built under R version 4.1.2
sample_coords <- tibble(
  x = c(43.00778, 42.99675),
  y = c(-87.94263, -87.90710)
) %>%
  st_as_sf(coords = c("y", "x"), crs = 4326) %>%
  summarise() %>%
  st_cast(., "LINESTRING")

sample_coords %>%
  ggplot() +
  geom_labelsf(label = "Label", fill = "red",
               text_only = TRUE)
#> Warning: Ignoring unknown parameters: text_only

Using the non-spatial geom_labelpath() with the same arguments, however, works as expected.

tibble(
  x = c(1, 2),
  y = c(0, 1)
) %>%
  ggplot(aes(x = x, y = y, group = 1)) +
  geom_labelpath(label = "Label", fill = "red",
                 text_only = TRUE)

I appreciate any guidance you can provide. Thanks again!

Created on 2022-03-02 by the reprex package (v2.0.1)

@teunbrand
Copy link
Collaborator

Hi there,

Thanks for reporting the issue, I can confirm that this isn't currently handled as you'd expect. I'd know how to activate the text parameters, but I'm not sure how I'd go about the fill aesthetic, since it is ambiguous whether it should apply to the label or the fill of potential polygons in the geometry. @AllanCameron, you probably have a better idea how this works than I do, should we make a box_fill aesthetic that defaults to the fill aesthetic?

@AllanCameron
Copy link
Owner

The aesthetics work a bit differently within the sf geoms, and as Teun says, the fill aesthetic is already used. Instead, I used a boxfill aesthetic for geom_labelsf, which probably isn't documented very well. Having text_only is also ambiguous when you have collections of linestrings and polygons - what exactly would you leave out the plot?

However, it is possible to achieve what you want using the current version without much trouble:

library(tidyverse)
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(geomtextpath)

sample_coords <- tibble(
  x = c(43.00778, 42.99675),
  y = c(-87.94263, -87.90710)
) %>%
  st_as_sf(coords = c("y", "x"), crs = 4326) %>%
  summarise() %>%
  st_cast(., "LINESTRING")

sample_coords %>%
  ggplot() +
  geom_labelsf(label = "Label", boxfill = "red",
               linewidth = 0)

Created on 2022-03-02 by the reprex package (v2.0.1)

@Pecners
Copy link
Author

Pecners commented Mar 2, 2022

Ah, got it. I only included the text_only piece as an example, but the real thing I was trying to do was fill the label. So, the boxfill option solves it for me. Thanks for the prompt attention here!

@AllanCameron
Copy link
Owner

I'll leave this open until I get round to improving the docs for this feature. Thanks for raising it @Pecners

@teunbrand
Copy link
Collaborator

I used a boxfill aesthetic for geom_labelsf

Excellent foresight, Allan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants