R語言畫圖——添加數學表達式和R2
代碼如下:
filepath <- file.choose()
df1 <- read.csv(filepath, header = T)
df1
library(ggplot2)
QTs <- ggplot(data = df1, aes(x = Ts, y = Q10, shape = factor)) +
geom_point(size = 3) +
scale_shape_manual(values = c(1, 17)) +
#白天的擬合曲線(實線)
stat_function(fun = function(x)1.5015*exp(x*(-0.009)),
color = "black", size = 1) +
#晚上的擬合曲線(虛線)
stat_function(fun = function(x)1.4864*exp(x*(-0.009)),
color = "black", size = 1, linetype = "dashed") +
annotate("text", x = 20, y = 2, parse = TRUE, label = "y == 1.5015*e^{-0.009*x}", size = 4) +
annotate("text", x = 20, y = 1.93, label = "atop(R^2==0.3174)", parse = TRUE) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),
panel.border = element_rect(colour = "black", fill = NA),
legend.position = "none") +
xlab("Soil temperature")
QTs
如圖:截取一部分圖片
補充
昨天,騷粉光榮退役。
新杯子強勢登場!