散点图
abundance = data.frame(lncount = c(13, 865, 1800), lnedna = c(4.72, 5.05, 5.22, 5.24,
5.36, 5.71, 5.63, 5.97,
6.08, 6.20, 6.43, 6.54))
xyplot(lnedna ~ lncount, data = abundance,
xlab = "Mussel Count by Snorkel Survey",
ylab = "eDNA concentraion (gene sequence/Liter) on log scale",
main = "Mussel Abundance")添加拟合线
abline(lm(lnedna ~ lncount))这是我在尝试添加回归行时不断得到的错误: error in eval(expr,envir,enclos):找不到对象'lnedna‘
lnedna可以很好地制作散点图,为什么不添加回归线呢?
发布于 2017-12-23 06:34:20
看起来您需要在xyplot调用中添加abline:
lattice::xyplot(lnedna ~ lncount, data = abundance,
panel = function(x, y) {
lattice::panel.xyplot(x, y)
lattice::panel.abline(lm(y ~ x))
},
xlab = "Mussel Count by Snorkel Survey",
ylab = "eDNA concentraion (gene sequence/Liter) on log scale",
main = "Mussel Abundance")发布于 2017-12-23 07:07:30
我不能用plot()重现你的答案。感谢hrabel提供的网格答案。这要归功于他。
ggplot2
library(ggplot2)
fit <- lm(lnedna ~ lncount, data = abundance)
ggplot(data = abundance, aes(x = lncount, y = lnedna))+
geom_point()+
geom_smooth(method = "lm", se = FALSE)+
xlab("Mussel Count by Snorkel Survey")+
ylab("eDNA concentraion (gene sequence/Liter) on log scale")+
ggtitle("Mussel Abundance")+
annotate("text" ,x = 1300, y = 6.13, label = paste("R-squared = ", summary(fit)$r.squared))

晶格(来自下面的hrabel )
lattice::xyplot(lnedna ~ lncount, data = abundance,
panel = function(x, y) {
lattice::panel.xyplot(x, y)
lattice::panel.abline(lm(y ~ x))
lattice::panel.text(1300, 6.13, paste("R-squared = ", summary(fit)$r.squared), sep = "")
},
xlab = "Mussel Count by Snorkel Survey",
ylab = "eDNA concentraion (gene sequence/Liter) on log scale",
main = "Mussel Abundance")

https://stackoverflow.com/questions/47948046
复制相似问题