使用 plotly- R 更改 3d 散点图的边距

Changing margins of a 3d scatter plot using plotly- R

我正在使用 plotly 生成 3D 散点图,请参阅下面的示例代码:

library(plotly)

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')),
     title = "Example plot")

当我下载情节的静态图像时,图像顶部没有 space,而且标题看起来几乎被截断了。有没有办法调整 3D 图上的边距来解决这个问题?尝试通过指定 layout 来调整边距会产生错误:

'scatter3d' objects don't have these attributes: 'margin'

也许您试图在错误的地方添加 margin。以下确实有效:

layout(scene = list(xaxis = list(title = 'Weight'),
                    yaxis = list(title = 'Gross horsepower'),
                    zaxis = list(title = '1/4 mile time')),
       title = "Example plot", margin = list(t = -1))