Skip to content

Recent changes to geom_label() #5419

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

Closed
aphalo opened this issue Sep 13, 2023 · 3 comments
Closed

Recent changes to geom_label() #5419

aphalo opened this issue Sep 13, 2023 · 3 comments

Comments

@aphalo
Copy link
Contributor

aphalo commented Sep 13, 2023

@teunbrand
This is just a quick question, to help me debug why two geometries in 'ggpp' (geom_label_s() and geom_label_pairwise()), based on code similar to that in the old version of geom_label() are silently failing to display the grobs for the text and box of the label under the current 'ggplot2' under development. Has anything changed in 'ggplot2' in how grobs (a grobTree in this case) are added? Second question, is there already some schedule for the release of 'ggplot2' 3.5.0?
Ideally, there would be solution to this problem, that would work with 3.4.0 and earlier as well as 3.5.0.

Thanks in advance.

Of the plots below, the one at the top is with 'ggplot' installed a couple of hours ago from GitHub. (954924b). The plot at the bottom is with 'ggplot2' 3.4.3 installed from CRAN. This example is from the documentation.

library(ggpp)
my.cars <- mtcars
my.cars$name <- rownames(my.cars)
p1 <- ggplot(my.cars, aes(factor(cyl), mpg)) +
          geom_boxplot(width = 0.33)

# With a factor mapped to x, highlight pairs

my.pairs <-
   data.frame(A = 1:2, B = 2:3, bar.height = c(12, 30),
                     p.value = c(0.01, 0.05678))
p1 +
   geom_label_pairwise(data = my.pairs,
                       aes(xmin = A, xmax = B,
                           y = bar.height,
                           label = sprintf("italic(P)~`=`~%.2f", p.value)),
                       colour = "red", size = 2.75,
                       arrow = grid::arrow(angle = 30,
                                           length = unit(1.5, "mm"),
                                           ends = "both"),
                       parse = TRUE)

image

image

@teunbrand
Copy link
Collaborator

Hi Pedro,

Has anything changed in 'ggplot2' in how grobs (a grobTree in this case) are added?

For geom_label() we've changed the implementation of how the drawing functions work because we wanted to support an angle aesthetic (among others). More details in #5030. For {ggpp} a quick glance gives me the intuition that in the lines below, the cl = "labelgrob" is not doing what it used to.

https://github.com/aphalo/ggpp/blob/175b38f54a73f66b7e44ef58121f51f23e55f6d6/R/geom-label-linked.r#L262-L263C94

We simplified the class away because we saw a simpler solution that didn't need the grid::makeContent methods for this class.

Second question, is there already some schedule for the release of 'ggplot2' 3.5.0?

Unfortunately I don't have a detailed grasp on this, but a meatier, non-hotfix release might come out sometime this year.

Ideally, there would be solution to this problem, that would work with 3.4.0 and earlier as well as 3.5.0.

I suspect that the development labelGrob() implementation would also fit with previous versions, so if you're copying the grob constructor, I'd try the new one.

@aphalo
Copy link
Contributor Author

aphalo commented Sep 14, 2023

Hi Teun,
I will try your suggested solution.
Many thanks!

@aphalo
Copy link
Contributor Author

aphalo commented Sep 14, 2023

Worked. Problem solved. Thanks again.

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

2 participants