代码之家  ›  专栏  ›  技术社区  ›  Ratnanil

R:具有小倍数/子批次的绘图纵横比

  •  3
  • Ratnanil  · 技术社区  · 7 年前

    我已经贴了这个 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。另一个有任意的长宽比。 enter image description here 以下是此绘图的交互式版本的链接: https://plot.ly/~rata_zhaw/1/

    有趣的是,如果我选择 shareX = T 在里面 subplot() ,整个第一列具有正确的纵横比。如果我选择什么都不会改变 shareY = T enter image description here

    下面是第二个情节的互动版本的链接: https://plot.ly/~rata_zhaw/3/

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

    plots[[10]] %>%
      layout(yaxis = list(scaleanchor  = "x")) %>%
      hide_legend()
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Stéphane Laurent    7 年前

    那怎么办

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

    enter image description here