【问题标题】:Adjust position of stats in ggpubr调整 ggpubr 中统计信息的位置
【发布时间】:2021-01-19 03:58:00
【问题描述】:

我有以下代码:

 library(ggpubr)
 ggscatter(mtcars[mtcars$cyl==4,], x = "drat", y = "wt", 
     add = "reg.line", add.params = list(color = "black", fill = "grey"), 
     conf.int = TRUE, cor.method = "spearman", cor.coef = TRUE)

如何将统计数据的位置(“R=-0.47,p=0.14”)向右更改?一直到右边还是中间?

【问题讨论】:

    标签: r ggplot2 ggpubr


    【解决方案1】:

    试试这个。您可以使用cor.coeff.args 选项来启用相关标签的位置。代码如下:

    library(ggpubr)
    ggscatter(mtcars[mtcars$cyl==4,], x = "drat", y = "wt", 
              add = "reg.line", add.params = list(color = "black", fill = "grey"), 
              conf.int = TRUE, cor.method = "spearman", cor.coef = TRUE,
              cor.coeff.args = list(label.x = 4.7, label.sep = "\n"))
    

    输出:

    或者这个选项保持原来的风格不变:

    #Code 2
    ggscatter(mtcars[mtcars$cyl==4,], x = "drat", y = "wt", 
              add = "reg.line", add.params = list(color = "black", fill = "grey"), 
              conf.int = TRUE, cor.method = "spearman", cor.coef = TRUE,
              cor.coeff.args = list(label.x = 4.5))
    

    输出:

    【讨论】:

      【解决方案2】:

      我们可以使用tidyverse 语法来做filter 然后利用stat_cor

      library(dplyr)
      library(ggpubr)
      mtcars %>% 
        filter(cyl == 4) %>% 
        ggscatter(x = 'drat', y = 'wt', add = "reg.line", a
         dd.params =  list(color = "black", fill = "grey"), conf.int = TRUE, cor.method = "spearman") +
         stat_cor(label.x.npc = 0.8, label.y.npc = 0.5)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-15
        • 2019-06-28
        • 2014-04-29
        • 1970-01-01
        • 2014-05-27
        相关资源
        最近更新 更多