Skip to content

Subscript out of bounds when running ggplotly on a working gg object #6656

@MatteoCe

Description

@MatteoCe

Hi tidyverse guys!

I think I found a bug in the new ggplot2 version, after updating to 4.0.0, when used in conjunction with plotly. Reverting to 3.5.2 gives no error, so I guess it's a new bug. It occurs when running ggplotly on a (apparently) working gg object, giving:

Error in pm[[2]] : subscript out of bounds

Here's the code giving the error:

library(sf)
library(ggplot2)

df <- data.frame(
    Stazione = c("Station1", "Station2"),
    Ora = c("12:00", "15:30"),       # keep as HH:MM
    color_val = c("red", "blue"),
    Longitudine = c(9.1900, 9.2000),
    Latitudine = c(45.4642, 45.4700)
)

# Convert to sf
df <- st_as_sf(df, coords = c("Longitudine", "Latitudine"), crs = 4326)

# Plot
gg <- ggplot() +
    geom_sf(
        data = df,
        aes(
            text = paste("Stazione:", Stazione, "<br>Ora:", Ora),  # use Ora directly
            customdata = Stazione
        ),
        color = report_date_sf$color_val, size = 2, shape = 2
    ) +
    theme_minimal()

gg

ggplotly(gg, tooltip = "text", source = "station_map")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions