R绘图-ggplot2包绘制磺基水杨酸浓度比与吸光度的关系

效果不错

效果图.jpg

原理

对于稳定性强、解离度小,且只有一种配合物组成的配位比计算可以使用等摩尔系列法:
在溶液中保持c_M+c_R=c_{总}的前提下,改变c_Mc_R的相对量,
当N值\frac{配体}{配体+中心离子}\frac{c_R}{c_总})达到最大时,即配合物M_{Rn}浓度最大,则\frac{c_R}{c_M}的值就是配合物的配位比

等摩尔系列法_2.png

绘图实践

原始数据在execl里,长这样
原始数据.jpg
安装和加载包
# install.packages("ggplot2")
# install.packages("readxl")

library(ggplot2)  
library(readxl)
读取文件,用前三个和后三个点拟合出直线
record = read_excel("C:/Users/Administrator/Desktop/磺基水杨酸吸光度.xlsx")

record = as.data.frame(lapply(record[, 3:4], as.numeric)) 

first_three <- record[1:3, ]  
last_three <- record[(nrow(record) - 2):nrow(record), ] 
提取斜率和截距算交点
lm_first <- lm(A ~ N, data = first_three)    
lm_last <- lm(A ~ N, data = last_three)    

# 提取模型的斜率和截距  
slope_first <- coef(lm_first)[2]  
intercept_first <- coef(lm_first)[1]  

slope_last <- coef(lm_last)[2]  
intercept_last <- coef(lm_last)[1]  

# 计算交点  
x_intersection <- (intercept_last - intercept_first) / (slope_first - slope_last)  
y_intersection <- slope_first * x_intersection + intercept_first  
输出交点坐标可以用这句cat("交点坐标为: (", x_intersection, ", ", y_intersection, ")\n", sep="")
交点坐标.jpg
在初始点和交点之间生成一万个点,让图像尽可能连续
# 创建扩展的数据点(只到交点)  
x_first <- seq(min(first_three$N), x_intersection, length.out = 10000)  
y_first <- slope_first * x_first + intercept_first  

x_last <- seq(x_intersection, max(last_three$N), length.out = 10000)  
y_last <- slope_last * x_last + intercept_last  

# 将直线数据放入dataframe中  
line_first <- data.frame(N = x_first, A = y_first)  
line_last <- data.frame(N = x_last, A = y_last)  
画图,一共六个元素:原始数据点、曲线、拟合直线两条、交点、交点坐标和理论最大值(浓度比为0.5)的坐标
ggplot(data = record, aes(x = N, y = A)) +  
  geom_point() +  
  labs(title = "磺基水杨酸物质的量分数和吸光度",   
       x = "磺基水杨酸/(磺基水杨酸+铁离子)",   
       y = "吸光度") +  
  
  geom_smooth(method = "loess", se = FALSE, span = 0.5, na.rm = T, color = "cornflowerblue", linewidth = 0.9) +  
  
  annotate("point", x = x_intersection, y = y_intersection, color = "red", size = 3) +  
  annotate("text", x = x_intersection, y = y_intersection,   
           label = paste("(", sprintf("%.2f", x_intersection), ", ", sprintf("%.2f", y_intersection), ")", sep = ""),   
           hjust = -0.3, color = "red") + 
  annotate("text", x = record$N[6], y = record$A[6],
           label = paste("(", sprintf("%.2f", record$N[6]), ",", sprintf("%.2f", record$A[6]), ")", sep = ""),
           vjust  = -0.9) +
  
  geom_line(data = line_first, aes(x = N, y = A), color = "red", linetype = "dashed", size = 0.5) +  
  geom_line(data = line_last, aes(x = N, y = A), color = "red", linetype = "dashed" , size = 0.5) + 
  theme_minimal()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容