【问题标题】:Changing margins of a 3d scatter plot using plotly- R使用 plotly-R 更改 3d 散点图的边距
【发布时间】:2019-01-14 19:49:25
【问题描述】:

我正在使用 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")

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

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

【问题讨论】:

    标签: r r-plotly


    【解决方案1】:

    也许您尝试在错误的位置添加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))
    

    【讨论】:

      猜你喜欢
      • 2018-06-24
      • 2021-04-17
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2017-01-17
      • 2018-10-27
      相关资源
      最近更新 更多