[R] Adding regression line to each individual plot in a window with multiple plots

Jake William Andrae jake.andrae at adelaide.edu.au
Wed Jan 18 02:04:51 CET 2017


Hi Everyone,



I've constructed a script that adds multiple plots to the plot window, but I'm having a bit of trouble adding a regression line to each individual plot. Of course, the regression lines will vary depending on the variables plotted against one another. I've attached the script.


#Growing season
#Construction of plots
# 12 figures arranged in 3 rows and 4 columns
attach(mtcars)
par(mfrow=c(3,4), mar = c(.6,.5,.6,1), oma = c(15,4,2,2), xpd = NA)
#Concentration
plot(Growing_season_precipitation, Concentration, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(0,500), xlab = NA, ylab = "Concentration", xaxt='n', pch=21,  bg='black', abline(lm(Growing_season_precipitation~Concentration)))
plot(Growing_season_VPD, Concentration, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21,  bg='black', yaxt='n')
plot(Growing_season_Rhmax, Concentration, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21,  bg='black', yaxt='n')
plot(Growing_season_temperature, Concentration, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(0,500), xlab = NA, ylab = "", xaxt='n', pch=21,  bg='black', yaxt='n')
#ACL
plot(Growing_season_precipitation, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(28,32), xlab = "", ylab = "ACL", xaxt='n',  pch=21,  bg='black')
plot(Growing_season_VPD, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(28,32), xlab = "", ylab = "", xaxt='n',  pch=21,  bg='black', yaxt='n')
plot(Growing_season_Rhmax, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(28,32), xlab = "", ylab = "", xaxt='n',  pch=21,  bg='black', yaxt='n')
plot(Growing_season_temperature, ACLTotal, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(28,32), xlab = "", ylab = "", xaxt='n',  pch=21,  bg='black', yaxt='n')
#CPI
plot(Growing_season_precipitation, CPITotal, xaxs = "i", yaxs = "i", xlim = c(0, 700), ylim = c(0,30), xlab = "Total precipitation (mm)", ylab = "CPI",  pch=21,  bg='black')
plot(Growing_season_VPD, CPITotal, xaxs = "i", yaxs = "i", xlim = c(0.6, 1.8), ylim = c(0,30), xlab = "Average daily VPD (kpa)", ylab = "",  pch=21,  bg='black', yaxt='n')
plot(Growing_season_Rhmax, CPITotal, xaxs = "i", yaxs = "i", xlim = c(35, 60), ylim = c(0,30), xlab = "Average daily RHmax (%)", ylab = "",  pch=21,  bg='black', yaxt='n')
plot(Growing_season_temperature, CPITotal, xaxs = "i", yaxs = "i", xlim = c(20,34), ylim = c(0,30), xlab = "Average daily temperature (oC)", ylab = "",  pch=21,  bg='black', yaxt='n')
#Plot main title
title(main="Growing season (June-November, inclusive)",outer=T)

Any help would be greatly appreciated!



	[[alternative HTML version deleted]]



More information about the R-help mailing list