plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Density plot draws unwanted outlines (similar to previously-removed release of ggplot2)

Open wcwr opened this issue 3 years ago • 2 comments

A density plot created with ggplot2 which has no outline then has an outline drawn when used with ggplotly. Relevant changelog for ggplot2.

Simple version of minimal reprex:

mtcars <- mtcars

p <- ggplot(mtcars, aes(x=disp)) + geom_density()
ggplotly(p)``

image

A workaround for this simple example (proposed by MrFlick on stackoverflow) was to use stat_density :

p <- ggplot(mtcars, aes(x=disp)) + stat_density(geom="line")
ggplotly(p)``

image

However, my 'real' data has multiple groups with different distributions. In this case, ggplotly still draw the unwanted outline, but also cannot be fixed this time by stat_density. Example:

p <- ggplot(mtcars, aes(x=disp, group=carb, color=carb)) + geom_density()
ggplotly(p)

p2 <- ggplot(mtcars, aes(x=disp, group=carb, color=carb)) + stat_density(geom="line")
ggplotly(p2)

image

wcwr avatar Jun 22 '21 13:06 wcwr

Ancient issue, I know, but..

p <- ggplot(mtcars, aes(x=disp, group=carb, color=carb)) + 
  stat_density(geom="line", position="identity")
  
ggplotly(p)

image

johnbaums avatar Jun 20 '23 00:06 johnbaums

Ancient issue, I know, but..

p <- ggplot(mtcars, aes(x=disp, group=carb, color=carb)) + 
  stat_density(geom="line", position="identity")
  
ggplotly(p)

image

This works, thanks!

wcwr avatar Jun 21 '23 12:06 wcwr