调整统计数据在 ggpubr 中的位置
Adjust position of stats in ggpubr
我有以下代码:
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") 的位置向右移动?一直向右还是向中间?
试试这个。您可以使用 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))
输出:
我们可以使用 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)
我有以下代码:
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") 的位置向右移动?一直向右还是向中间?
试试这个。您可以使用 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))
输出:
我们可以使用 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)