How to align multiple mesh3D plot side by side in Rmarkdown HTML output

Hello,

I plotted 3 mesh3D plots by plotly in R and would like to put them side by side (one row or any layout) in Rmarkdown HTML output. I tried the subplot function but it merged all plots into one plotyly object/panel instead of 3 separate panels. Could you please help? Below is just a toy example I modified from this demo Mixed subplots in R

Thanks a lot

#' ---
#' title: " "
#' author: " "
#' date: "`r format(Sys.time(), '%B, %Y')`"
#' linkcolor: blue
#' output:
#'   html_document:
#'     fig_caption: yes
#'     theme: spacelab #sandstone #spacelab #flatly
#'     highlight: default
#'     toc: FALSE
#'     toc_depth: 3
#'     number_sections: FALSE
#'     toc_float:
#'      smooth_scroll: FALSE
#' ---

#' ```{css, echo=FALSE}
#' pre {
#'   max-height: 300px;
#'   overflow-y: auto;
#' }
#'
#' pre[class] {
#'   max-height: 600px;
#' }
#' ```

#' ### Plot
#+ warning = FALSE, message = FALSE, comment = NA

library(plotly)
library(anglr)
library(maptools)

data(wrld_simpl)

map1 <- subset(wrld_simpl,
               NAME %in% c("Indonesia", "Papua New Guinea", "New Zealand", "Australia"))
## DEL model (like TRI in silicate)
delmesh <-  anglr::globe(anglr::DEL(map1, max_area = 0.5))
mesh <- as.mesh3d(delmesh)


# plot point cloud
x <- mesh$vb[1,]
y <- mesh$vb[2, ]
z <- mesh$vb[3,]
m <- matrix(c(x,y,z), ncol=3, dimnames=list(NULL,c("x","y","z")))

# colours in z don't make sense here, need to mafig object aesthetics above
zmean <- apply(t(mesh$it),MARGIN=1,function(row){mean(m[row,3])})

library(scales)
facecolor = colour_ramp(
  brewer_pal(palette="RdBu")(9)
)(rescale(x=zmean))

fig1 <- plot_ly(
  x = x, y = y, z = z,
  i = mesh$it[1,]-1, j = mesh$it[2,]-1, k = mesh$it[3,]-1,
  facecolor = facecolor,
  type = "mesh3d"
)

fig1
fig1
fig1

# subplot
fig <- subplot(fig1, fig1, fig1, nrows = 2)
fig <- fig %>% layout(title = "Walmart Store Openings by Year",
                      xaxis = list(domain=list(x=c(0,0.5),y=c(0,0.5))),
                      scene = list(domain=list(x=c(0.5,1),y=c(0,0.5))),
                      xaxis2 = list(domain=list(x=c(0.5,1),y=c(0.5,1))),
                      showlegend=FALSE,showlegend2=FALSE)

fig

When plotting separately, it worked
image

But the joint one seems to merge 3 figures in one
image

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.