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

Support for ggplot stacked geom_area plots? #2320

Open
mot12341234 opened this issue Nov 27, 2023 · 1 comment
Open

Support for ggplot stacked geom_area plots? #2320

mot12341234 opened this issue Nov 27, 2023 · 1 comment

Comments

@mot12341234
Copy link

mot12341234 commented Nov 27, 2023


I have a stacked geom_area plot in ggplot which looks fine, but somehow the ggplotly version shows empty. Below is the toy example. (the issue seems to do with position_fill(), if getting rid of it, the plot can run normally)..

R version: 4.3.2, plotly version: 4.10.3

library(tidyverse)
library(plotly)

df <- expand_grid(tibble(x = seq(10), y = seq(10)), g = letters[1:5])
pl <- df %>%
  ggplot() +
  geom_area(aes(x = x, y = y, fill = g), position = 'fill')
 
ggplotly(pl)
@trekonom
Copy link
Contributor

trekonom commented Apr 27, 2024

This issue is most likely due to a change introduced in ggplot2 3.4.0 which now defaults to stat="align" (which does some form of interpolation) for geom_area and which is not fully supported by ggplotly (a related issue arises when it comes to the tooltips, see this SO question).

But for your case that can be fixed by setting stat="identity" in geom_area:

library(plotly, warn=FALSE)
#> Loading required package: ggplot2

df <- tidyr::expand_grid(
  tibble::tibble(x = seq(10), y = seq(10)),
  g = letters[1:5]
)
pl <- ggplot(df) +
  geom_area(aes(x = x, y = y, fill = g),
    position = "fill", stat = "identity"
  )

ggplotly(pl)

Created on 2024-04-27 with reprex v2.1.0

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