【问题标题】:merging plotly graphs r合并绘图图r
【发布时间】:2019-05-29 22:23:51
【问题描述】:

我正在尝试在一个视图中合并不同的情节图。我遇到的问题是标准的subplot() 函数将图合并在一起。有没有办法将它们分开,例如 par(mfrow) 或 ggplot 的 grid.arrange() 函数?

【问题讨论】:

    标签: r plotly subplot


    【解决方案1】:

    试试ggarrange()

    # Box plot (bp)
    bxp <- ggboxplot(ToothGrowth, x = "dose", y = "len",
                     color = "dose", palette = "jco")
    bxp
    # Dot plot (dp)
    dp <- ggdotplot(ToothGrowth, x = "dose", y = "len",
                     color = "dose", palette = "jco", binwidth = 1)
    
    # Bar plot (bp)
    bp <- ggbarplot(mtcars, x = "name", y = "mpg",
              fill = "cyl",               # change fill color by cyl
              color = "white",            # Set bar border colors to white
              palette = "jco",            # jco journal color palett. see ?ggpar
              sort.val = "asc",           # Sort the value in ascending order
              sort.by.groups = TRUE,      # Sort inside each group
              x.text.angle = 90           # Rotate vertically x axis texts
              )
    bp + font("x.text", size = 8)
    # Scatter plots (sp)
    sp <- ggscatter(mtcars, x = "wt", y = "mpg",
                    add = "reg.line",               # Add regression line
                    conf.int = TRUE,                # Add confidence interval
                    color = "cyl", palette = "jco", # Color by groups "cyl"
                    shape = "cyl"                   # Change point shape by groups "cyl"
                    )+
      stat_cor(aes(color = cyl), label.x = 3)       # Add correlation coefficient
    sp
    
    ggarrange(bxp, dp, bp + rremove("x.text"), 
              labels = c("A", "B", "C"),
              ncol = 2, nrow = 2)
    

    示例来自here

    【讨论】:

    • 谢谢你,这样做的问题是我失去了情节提供的交互性。
    猜你喜欢
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2022-12-06
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多