Skip to content

Error with hjust = "right" when used together with size aesthetic #5614

Closed

Description

@aphalo

@teunbrand @thomasp85 This bug breaks unit tests in 'ggpp', but I can reproduce the bug using 'ggplot2' on its own.

The first example below used to work without error in 'ggplot2' (==3.4.4.9000) until quite recently (or at least 'ggpp' tests worked), but is now broken. Based on the second and third examples below, it seems that the combined use of the size aesthetic and hjust = "right" is what triggers the error.

With the current version here at GitHub I see:

library(ggplot2)
packageVersion("ggplot2")
#> [1] '3.4.4.9000'
packageDate("ggplot2")
#> [1] "2023-12-24"

mycars <- mtcars
mycars$name <- rownames(mycars)

ggplot(mycars, aes(wt, mpg, label = name)) +
  geom_text(aes(size = wt), nudge_x = -0.1, hjust = "right")
#> Error in 1 - hjust[is_case]: non-numeric argument to binary operator

ggplot(mycars, aes(wt, mpg, label = name)) +
  geom_text(nudge_x = -0.1, hjust = "right")

ggplot(mycars, aes(wt, mpg, label = name)) +
  geom_text(aes(size = wt), nudge_x = -0.1, hjust = 1)

Created on 2023-12-25 with reprex v2.0.2

Activity

  1. teunbrand commented on Dec 26, 2023

    @teunbrand
    Collaborator

    Thanks @aphalo for catching this bug. The timing is perfect as we're currently revising what new bugs we may have introduced. I think the problem is currently in the legend key code, but we should definitely fix this for the upcoming release.

  2. added this to the ggplot2 3.5.0 milestone on Dec 26, 2023
  3. teunbrand commented on Jan 4, 2024

    @teunbrand
    Collaborator

    Considering this fixed by #5618.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions