我有这种情况:
library(ggplot2)
library(ggpubr)
# Load data
data("mtcars")
df <- mtcars
df$vs <- factor(df$vs, labels = c("Alpha", "Beta"))
df$MyFactor <- rep(c("White", "Black"), nrow(df)/2)
# Plotting
ggplot(df, aes(x=wt, y=mpg, group = vs))+
geom_point()+
geom_smooth(method = "lm")+
facet_wrap(~MyFactor)+
stat_cor(method = "pearson", label.y.npc="top", label.x.npc = "left", color = "black")+
theme_bw()
我想在
paste
标签上stat_cor
相对分组变量vs
(即Alpha
和Beta
)。因此,我使用了:
ggplot(df, aes(x=wt, y=mpg, group = vs))+
geom_point()+
geom_smooth(method = "lm")+
facet_wrap(~MyFactor)+
stat_cor(aes(label = paste(..group.., "- ", ..r.label.., ..p.label.., sep = "~`,`~")), method = "pearson", label.y.npc="top", label.x.npc = "left", color = "black")+
theme_bw()
然而,我的输出是:
如何获取我的 vs 分组标签?