【问题标题】:R: Plotly aspect ratio with small multiples / subplotsR:具有小倍数/子图的情节纵横比
【发布时间】:2018-12-04 11:29:52
【问题描述】:

我在两周前发布了这个as an issue on Github。既然转发问题“if the project maintainers don't respond in a reasonable amount of time”显然是可以的,所以我将问题发布在这里。

我想创建具有固定纵横比的小倍数。但是,只有一些图保留了正确的纵横比。根据我收集的信息,使用 plotly 设置固定的纵横比如下:layout(yaxis = list(scaleanchor = "x"))。考虑以下示例:

library(purrr)
library(plotly)

df <- data.frame(
  x = rep(1:5,25),
  y = rep(1:5,25),
  g = sort(rep(1:25,5))
)

plots <- df %>%
  split(.$g) %>%
  map(function(x){
    plot_ly(data = x, x = ~x, y = ~y, type = "scatter",mode = "lines") %>% add_lines()
  })

small_multiples <- subplot(plots,nrows = 5) %>%
  layout(yaxis = list(scaleanchor  = "x")) %>%
  hide_legend()

如果我绘制small_multiples,则只有第一个图(第 1 行,第 1 列)的纵横比为 1。另一个具有任意纵横比。 这是该情节的交互式版本的链接:https://plot.ly/~rata_zhaw/1/

有趣的是,如果我在subplot() 中选择shareX = T 选项,则整个第一列的纵横比都是正确的。如果我选择shareY = T,什么都不会改变

这是第二个情节的交互式版本的链接:https://plot.ly/~rata_zhaw/3/

如果我单独绘制任何图,则纵横比是正确的:

plots[[10]] %>%
  layout(yaxis = list(scaleanchor  = "x")) %>%
  hide_legend()

【问题讨论】:

    标签: r plot plotly r-plotly


    【解决方案1】:

    怎么样

    small_multiples <- subplot(plots,nrows = 5) %>%
      layout(scene = list(aspectration=list(x=1,y=1))) %>%
      hide_legend()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 2021-05-10
      • 2018-04-29
      相关资源
      最近更新 更多