gpt4 book ai didi

r - 将文本添加到点阵图?

转载 作者:行者123 更新时间:2023-12-04 09:32:22 26 4
gpt4 key购买 nike

有人可以告诉我如何向格图添加文本行。

我的代码是:

xyplot(Neff~Eeff,data=phuong,panel=mypanel,
col="black",
pch=18,xlab="Energy efficiency (%)",
ylab = "Nitrogen efficiency (%)", main="(a)")

这里 pane=mypanel是添加一个abline。
我想在 Eeff 和 Neff 之间添加一个线性回归方程到他们的图中。

谢谢!

最佳答案

因此,使用可重复的数据:

set.seed(1)

phuong <- data.frame(Eeff = rnorm(100,31))
phuong$Neff <- rnorm(100,19.7 + .36*phuong$Eeff)

# Create the lm object ahead of time
lm1 <- lm(Neff ~ Eeff, data = phuong)

# Create the character string that you want to print
tp <- sprintf("%s=%.1f + %.2f %s", all.vars(formula(lm1))[1],
coef(lm1)[1], coef(lm1)[2], all.vars(formula(lm1))[2])

# Change the mypanel function to use the lm1 object
mypanel<-function(x,y,...){
panel.xyplot(x, y, ...)
panel.abline(lm1)
panel.text(30,33,labels=tp)
}

library(lattice)

# and off we go.

xyplot(Neff~Eeff,data=phuong,panel=mypanel,
col="black",
pch=18,xlab="Energy efficiency (%)",
ylab = "Nitrogen efficiency (%)", main="(a)")

enter image description here

关于r - 将文本添加到点阵图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12248116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com