我有以下代码,
d <- mtcars
library(plotly)
# box on top / hist bottom
boxplot<-plot_ly(d, x = ~mpg, type = "box", name = "mpg")
histogram<-plot_ly(d, x = ~mpg, type = "histogram", name = "mpg")
我想将箱线图放在直方图的顶部,如下图所示:
我尝试使用 subplot() R 函数,但没有得到所需的结果
subplot(boxplot,histogram) %>% layout(showlegend=FALSE)
提前致谢!
您有shareX
共享相同 X 轴的nrows
参数和垂直放置它的参数:
subplot(boxplot,histogram,nrows=2,shareX=TRUE) %>% layout(showlegend=FALSE)
如果您设置,您还可以消除线条:
ax <- list(
showgrid = FALSE
)
boxplot<-plot_ly(d, x = ~mpg, type = "box", name = "mpg")%>%
layout(showlegend=FALSE,xaxis = ax,yaxis = ax)
histogram<-plot_ly(d, x = ~mpg, type = "histogram", name = "mpg")%>%
layout(showlegend=FALSE,xaxis = ax,yaxis = ax)
subplot(boxplot,histogram,nrows=2,shareX=TRUE)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句