plotly.R
plotly.R copied to clipboard
Add support for geom_boxplot(stat="identity") in ggplotly or similar for plot_ly boxplot
I'm using ggplot2 to create boxplots which I'd then like to make interactive by converting to a plotly object. What I need to be able to do however is use my own computed values for the min, max, lower, upper, and middle values of the boxplot. This is possible in ggplot by using stat="identity" in geom_boxplot() and setting the values within aes(). When I then pass the ggplot object to ggplotly however nothing renders, I just get an empty axis. I think this is because plotly tries to internally calculate the quartiles etc when converting the box plot (which it then can't do because I've not given it appropriate data).
Would it therefore be possible to add support for setting the boxplot values either through the ggplotly conversion or directly using a plot_ly() boxplot?
Thanks
p.s. a simple example of what I'd like to convert can be found at the end of the geom_boxplot documentation (http://docs.ggplot2.org/current/geom_boxplot.html).
This won't be possible until this gets addressed https://github.com/plotly/plotly.js/issues/242
Now that the above issue has been fixed in plotly/plotly.js#4432, can we please reconsider this?
It's currently possible via add_trace()
:
plot_ly() %>%
add_trace(lowerfence = 0, q1 = 1, median = 3, q3 = 5, upperfence = 10, type = "box")
Reopening though since add_boxplot()
probably shouldn't error if you provide q1
/median
/q3
instead of x
/y
ggplotly
appears to also have issues with this. The following gives a boxplot with no data.
y <- rnorm(100)
(data.frame(
x = 1,
y0 = min(y),
y25 = quantile(y, 0.25),
y50 = median(y),
y75 = quantile(y, 0.75),
y100 = max(y)
) %>%
ggplot(aes(x)) +
geom_boxplot(
aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100),
stat = "identity"
)) %>%
plotly::ggplotly()
Is this issue going to be solved? I'm still having the same issue as @joshuablake on a similar code.
+1. I'm having the same issue as @joshuablake and @TucoFernandes. Please see question at https://stackoverflow.com/questions/75349810/using-plotly-with-ggpolot2-geom-plot-with-stat-identity-results-in-empty-canvas. Btw, this (using pre-computed quartile values in geom_boxplot) is necessary because plotly is unable to handle large datasests (in my case ~46 million rows). Thank you.
Anyone know if there's any update on this issue? I have the exact same issue as @joshuablake. I have to use precomputed values because of size and for validation purposes.
I'm having the exact same issue as @smritia @joshuablake