線形回帰の基本プロット

ここではbaseパッケージを用いた線形回帰のための二次元散布図と回帰直線を描いてみます.

データの読み込み

library(vegan)
phyto_metadata <- readRDS("phyto_metadata.obj")
species_ryuko_data <- readRDS("phyto_ryuko_data.obj")
species_richness <- apply(species_ryuko_data > 0, 1, sum)
total_abundance <- apply(species_ryuko_data, 1, sum)

二次元散布図+回帰直線

植物プランクトンのデータを使った場合

#Classical plot (base)
model01 <- lm(species_richness ~ phyto_metadata$temp)
plot(
  species_richness ~ phyto_metadata$temp, 
  type = "p", 
  cex = 3,
  xlab = "temperature",
  ylab = "species richness"
)
abline(model01,col = 4) #回帰直線

線形回帰のggplot

LS0tDQp0aXRsZTogIlLjga7ln7rmnKzjg5fjg63jg4Pjg4giDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQojIOe3muW9ouWbnuW4sOOBruWfuuacrOODl+ODreODg+ODiA0K44GT44GT44Gn44GvYmFzZeODkeODg+OCseODvOOCuOOCkueUqOOBhOOBn+e3muW9ouWbnuW4sOOBruOBn+OCgeOBruS6jOasoeWFg+aVo+W4g+Wbs+OBqOWbnuW4sOebtOe3muOCkuaPj+OBhOOBpuOBv+OBvuOBme+8jg0KDQojIyDjg4fjg7zjgr/jga7oqq3jgb/ovrzjgb8NCmBgYHtyfQ0KbGlicmFyeSh2ZWdhbikNCnBoeXRvX21ldGFkYXRhIDwtIHJlYWRSRFMoInBoeXRvX21ldGFkYXRhLm9iaiIpDQpzcGVjaWVzX3J5dWtvX2RhdGEgPC0gcmVhZFJEUygicGh5dG9fcnl1a29fZGF0YS5vYmoiKQ0Kc3BlY2llc19yaWNobmVzcyA8LSBhcHBseShzcGVjaWVzX3J5dWtvX2RhdGEgPiAwLCAxLCBzdW0pDQp0b3RhbF9hYnVuZGFuY2UgPC0gYXBwbHkoc3BlY2llc19yeXVrb19kYXRhLCAxLCBzdW0pDQpgYGANCiMjIOS6jOasoeWFg+aVo+W4g+Wbs++8i+WbnuW4sOebtOe3mg0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