plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.54k stars 622 forks source link

Some geoms always appear below others #866

Open jvgogh opened 7 years ago

jvgogh commented 7 years ago

Rendering of violin plots with box plots (to provide median & stddev) is in wrong order when using ggplotly.

library(ggplot2)
library(plotly)

p <- ggplot(iris,aes(Species,Sepal.Length))+
  geom_violin()+geom_boxplot(width=.1)
q <- ggplotly(p) 

the ggplot (p) will render as expected with violin plots: ggplot

the ggplotly (q) will render with the box plot behind the violin plot (and larger than expected): ggplotly

ifellows commented 5 years ago

This also affects other geoms. Is there a plan to address this issue?

###Sample gaussian distributions with 1, 2 and 3 modes.
df <- data.frame(
  "Distribution" = c(rep("Unimodal", 500),
                     rep("Bimodal", 250),
                     rep("Trimodal", 600)),
  "Value" = c(rnorm(500, 6, 1),
              rnorm(200, 3, .7), rnorm(50, 7, 0.4),
              rnorm(200, 2, 0.7), rnorm(300, 5.5, 0.4), rnorm(100, 8, 0.4))
)
library(ggplot)
library(ggforce)

p <- ggplot(df, aes(Distribution, Value, color=Distribution))+ geom_sina() + geom_boxplot( outlier.alpha=0)
p
p %>% ggplotly()

Note also that the outliers are incorrectly printed (see the black dots) when they should be transparent and the legend is incorrect. Related: #1114

ggplot2: image

plotly: screen shot 2019-03-07 at 2 37 54 pm

cpsievert commented 5 years ago

It seems the root issue here is some plotly.js traces are always drawn below other traces https://github.com/plotly/plotly.js/issues/3748

These examples should automatically fix themselves if and when plotly.js respects the ordering of traces...

ifellows commented 5 years ago

Thanks for looking into this. Is the outlier printing issue something that would automatically be fixed, or it that different?

cpsievert commented 5 years ago

That's a different problem that I have more control over.