[英]How to colour and move R squared equation to next line in ggplot2 facet_grid?
對於我需要的圖形尺寸,我希望 R 平方出現在下一行。 我還希望文本的顏色與因子z
的顏色相對應
x <- c(1:50)
y <- rnorm(50,4,1)
z <- rep(c("J","F","H","I","J","K","L","M","N","O"), each = 5)
df <- data.frame(x,y,z)
my.formula = y ~ x
ggplot(aes(x = x, y = y, color = z), data = df) +
geom_point() +
stat_summary(fun.data=mean_cl_boot, geom="errorbar", width=0.2, colour="black") +
stat_summary(fun = mean, color = "black", geom ="point", size = 3,show.legend = FALSE) +
geom_smooth(method="lm", formula = y ~ x ) +
stat_poly_eq(formula = my.formula, aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")), parse = TRUE, size = 2.5, col = "black")+
facet_grid(.~z, scales = "free") + theme_classic()
這是一種方法。
color = "black"
;atop
,請參閱?plotmath
。 atop
的結果不是左對齊,而是在這里。
ggplot(mapping = aes(x = x, y = y, color = z), data = df) +
geom_point() +
stat_summary(fun.data=mean_cl_boot, geom="errorbar", width=0.2, colour="black") +
stat_summary(fun = mean, color = "black", geom ="point", size = 3,show.legend = FALSE) +
geom_smooth(method="lm", formula = y ~ x ) +
stat_poly_eq(
formula = my.formula,
aes(label = paste("atop(", ..eq.label.., ",", ..rr.label.., ")")),
label.y = 0.9,
parse = TRUE,
size = 2.5
#, col = "black"
)+
facet_grid(.~z, scales = "free") +
theme_classic()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.