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

Empty objects in subplot

Open jianhaizhang opened this issue 5 years ago • 3 comments

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!

jianhaizhang avatar Jul 19 '20 00:07 jianhaizhang

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.

zhengzheli avatar Apr 28 '23 13:04 zhengzheli

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

jianhaizhang avatar May 01 '23 20:05 jianhaizhang

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)

zhengzheli avatar May 03 '23 23:05 zhengzheli