plotly.R
plotly.R copied to clipboard
Empty objects in subplot
An error arises when mix an empty object with ggplot-derived plotly in subplot
library(plotly); library(ggplot2)
df <- data.frame(dose=c("D0.5", "D1", "D2"), len=c(4.2, 10, 29.5))
p<-ggplot(data=df, aes(x=dose, y=len)) +geom_bar(stat="identity")
ply <- ggplotly(p)
# This gives an error.
subplot(ply, ply, ggplotly(ggplot()), nrows=1, shareX=F, shareY=F, margin=0, widths=c(0.3, 0.3, 0.3))
# This gives a warning.
subplot(ply, ply, plotly_empty(type = "scatter"), nrows=1, shareX=F, shareY=F, margin=0, widths=c(0.3, 0.3, 0.3))
What are the possible solutions? Thanks!
The above no longer gives an error, at least once I remove the widths argument to subplot. Thanks for sharing your code though, it helped me out.
Is it possible to avoid the warning?
subplot(ply, ply, plotly_empty(type = "scatter"), nrows=1, shareX=F, shareY=F, margin=0)
Warning message: Can only have one: config
It is caused by plotly_empty(), but we can use an empty ggplot instead such as:
ggplot_empty <- ggplot(mtcars, aes(hp, mpg)) + geom_blank()
subplot(ply, ply, ggplot_empty , nrows=1, margin=0)