我想检查两列数据之间的相关性,并将它们绘制到pdf文件中。有人可以告诉我该怎么做吗?
diff abund_mean
0 3444804.79
1 847887.02
2 93654.19
0 721692.76
2 382711.04
1 428656.65
1 120933.91
0 157528.72
1 159650.70
0 124602.80
0 90844.33
2 501825.37
1 270592.56
答案 0 :(得分:1)
你还需要情节还是只需要相关系数? 这给你带有r ^ 2的散点图:
pdf(file="myplot.pdf", width = 10, height =13) #create new pdf
plot(diff ~ abund_mean) #see data
abline(lm<- lm(diff ~ abund_mean)) #add regression to plot
legend("topright", bty="n", legend=paste
("R2 is", format(summary(lm)$adj.r.squared, digits=4))) #print the regr. coeff. on plot
dev.off() #end of pdf creation
summary(lm) #see all the regression coefficients (F-statistic, RSE, etc.)