将文字添加到点阵图? [英] Add text to lattice plot?
本文介绍了将文字添加到点阵图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何在格子图中添加文本行.
Could someone tell me how to add a text line to lattice plot.
我的代码是:
xyplot(Neff~Eeff,data=phuong,panel=mypanel,
col="black",
pch=18,xlab="Energy efficiency (%)",
ylab = "Nitrogen efficiency (%)", main="(a)")
此处pane=mypanel
用于添加退位.
我想在Eeff和Neff之间添加一个线性回归方程.
Here pane=mypanel
is to add an abline.
I want to add a linear regression equation between Eeff and Neff to their plot.
谢谢!
推荐答案
因此,使用可复制的数据:
So, with reproducible data:
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)")
这篇关于将文字添加到点阵图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文