inserting 3d cube (rgl package?) into blogdown post


I am trying to plot a 3d cube in blogdown. The code could be e.g.

plot3d(x, y, z, col = rainbow(1000), xlim = c(-4,4), ylim = c(-4, 4), zlim = c(-2, 2))
abclines3d(2, 3, 1, a = diag(3), col = "gray")

Unfortunately, when insertig the code from above into a blogdown post, the graph doesn't show up.
Any idea? My hunch is that this has something to do with the rgl package or possibly htmlwidgets? But I couldn't figure out what to do next.

To be clear, i don't have to use the rgl package necessarily. My primary goal is to produce a 3d cube with scattered dots.

Grateful for any hint! Many thanks.

Created on 2020-01-24 by the reprex package (v0.3.0)

Answering my own question since it might be helpful for others at a later point:

I managed to create a 3d cube in blogdown with plotly. No htmlwidget or someting similar needed.

mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)

p <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E')) %>%
  add_markers() %>%
  layout(scene = list(xaxis = list(title = 'Weight'),
                     yaxis = list(title = 'Gross horsepower'),
                     zaxis = list(title = '1/4 mile time')))

1 Like

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