r - 如何在 Facet 模式下定位 R 平方和方程?
问题描述
我想在刻面模式下显示每个图中的线性方程和 R 平方。到目前为止,这是我的代码。
library("ggplot2")
datos <- read.table("~/Documents/master2/plots/dosis_todos/datos.dat", header=TRUE, quote="\"")
ggplot(datos, aes(x = corriente, y = dosis, colour = cristal)) +
geom_point() + geom_smooth(method="lm", se=F) +
facet_wrap(~datos$cristal)
在此答案中阅读了有关 ggpmisc 的信息后,我尝试了
my.formula <- y ~ x
library("ggpmisc")
ggplot(datos, aes(x = corriente, y = dosis, colour = cristal)) +
geom_point() +
geom_smooth(method="lm", se=F, formula=my.formula) +
stat_poly_eq(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")), formula = my.formula, parse = TRUE) +
facet_wrap(~datos$cristal)
哪种方法有效,除了方程的位置对于每个情节都会下降,直到消失......
如果我将我的情节保存得足够大,我可以在 9 个情节中看到我的所有文本......下降。
所以我想问题是如何保持方程的位置和R平方信息的固定?
谢谢
附言。是的,我知道 N57 只有 3 分 :(
附言。这是我的数据的链接
解决方案
@murpholinox 是的,你是对的,'ggpmisc' 中的代码还不够聪明,无法检测到每个面板的不同颜色等美学值何时是唯一的。但是,可以手动定位方程,将数据单元中的位置传递给参数label.y
和/或label.x
。所以,有一个解决方法。
library("ggplot2")
library("ggpmisc")
datos <- read.table("datos.dat", header=TRUE, quote="\"")
my.formula <- y ~ x
ggplot(datos, aes(x = corriente, y = dosis, colour = cristal)) +
geom_point() +
geom_smooth(method="lm", se=F, formula=my.formula) +
stat_poly_eq(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
formula = my.formula, parse = TRUE, label.y = 0.9) +
ylim(0, 1) +
facet_wrap(~datos$cristal)
也可以将向量传递给label.y
和label.x
,以便可以为每个面板手动定位每个方程。
ggplot(datos, aes(x = corriente, y = dosis, colour = cristal)) +
geom_point() +
geom_smooth(method="lm", se=F, formula=my.formula) +
stat_poly_eq(aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
formula = my.formula, parse = TRUE,
label.y = c(rep(0.9, 6), rep(0.15, 2), 0.9)) +
ylim(0, 0.95) +
facet_wrap(~datos$cristal)
推荐阅读
- python - python-telegram-bot 在群聊中回复特定用户
- regex - URL 包含括号的模式的 .htaccess 重写规则
- excel - 如何在 VBA 用户窗体中修复日期 - 日期以不正确的格式输入工作表
- javascript - 如何在反应原生中过滤多个选择下拉字段中的数组值
- bash - 带参数执行
- angular - 如何以角度修复路线
- tcl - 在 TCL 中,当文件处于连续写操作时,是否可以读取和编辑文件
- python - 如何使用熊猫在excel中查找空白单元格?
- vue.js - Vue.js:服务器端应用程序的全局基本 URL
- typescript - 无法使用 sequelize-typescript 连接到 Heroku 的数据库