惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
爱范儿
爱范儿
Recent Announcements
Recent Announcements
AI
AI
V
Visual Studio Blog
H
Heimdal Security Blog
L
LINUX DO - 最新话题
Attack and Defense Labs
Attack and Defense Labs
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
人人都是产品经理
人人都是产品经理
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
S
Secure Thoughts
S
Security Affairs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
博客园 - Franky
阮一峰的网络日志
阮一峰的网络日志
Schneier on Security
Schneier on Security
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
Forbes - Security
Forbes - Security
The Cloudflare Blog
博客园 - 【当耐特】
酷 壳 – CoolShell
酷 壳 – CoolShell
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
有赞技术团队
有赞技术团队
博客园 - 司徒正美
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
NISL@THU
NISL@THU
C
Cybersecurity and Infrastructure Security Agency CISA
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
罗磊的独立博客
V
Vulnerabilities – Threatpost
S
Securelist
N
News and Events Feed by Topic
Cloudbric
Cloudbric
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V2EX - 技术
V2EX - 技术
小众软件
小众软件

Yorksite

Plog006:Pebble Time 2 到了! · Plog Plog005:忙碌的六月 · Plog Plog004:好吃好吃 · Plog Plog003:Until Then · Plog Plog002:春天花会开 · Plog Plog001:让人疲惫的AI与在战锤世界中仰泳,赞美欧姆尼赛亚? · Plog rhaeTree:一个基于 Rust 的进化树可视化编辑工具 · Articles 我的键盘快捷键们 · Articles 迟到的2025年度数码产品总结 · Articles 关于我和这个博客 · Info 买了一只十多年前的老 Pebble · Articles 盘点一下今年让我上头的那些游戏 · Articles 【吃了啥】新利查西菜馆 · Articles 根据Zotero数据库追踪新发表文献 · Articles 解决远程服务器上Singularity联网问题 · Articles 又是一个Mac软件列表 · Articles Vita3K存档转移到PSV实机 · Articles SnapGene创建多外显子基因结构 · Articles Rstudio也能用GitHub Copilot了 · Articles 双十一买了啥 · Articles 文献一团乱麻?试试PARA管理方法 · Articles 点名的风还是吹到了Blog · Articles 从Raindrop迁移到了Anybox · Articles 数据可视化——基本图形元素及其应用 · Articles 单变量异常值检测方法 · Articles 【读文献】单细胞分析最佳实践 · Articles Docker 打包 Shiny App · Articles 部署预印本追踪 TRxiv 到 Github Action · Articles Hello, again · Articles 1 dataset 100 visualizations 中有意思的可视化 · Articles 论文可视化配色简易指南 · Articles Karabiner 助力,让你的键盘操作快人一步 · Articles 我的植物组学数据库合集 Ver.20220528 · Articles 利用 n8n 打造飞书 RSS 推送机器人 · Articles 「#」的前世今生 · Articles 克服低效率恐惧,回归健康生活 · Articles 科研论文作图基本知识 · Articles 为什么我们不喜欢学习 · Articles
复现一张相关性图 · Articles
2023-05-30 · via Yorksite

复现一张相关性图

Published May 30, 2023

1 minutes read

前几天看到群里有人问如何画一张类似下图的、带拟合线与误差的相关性图,这里找点数据来演示一下怎么画。

demo 找了点数字画了个例子,假设数据读进来是这样的两列:

Untitled

绘图的部分我用了这些

leg <- theme(title=element_text(size=15), 
             axis.text.x=element_text(size=14),
             axis.text.y=element_text(size=14),
             legend.text=element_text(size=14))
label_text <- paste0("r = ", round(cor(subdata$Na,subdata$K),2))
library(ggplot2)
ggplot(subdata, aes(x = log(Na), y = log(K))) +
  geom_point(size = 2,color = "#31705a") +
  stat_smooth(method = "lm", color = "#31705a")+
  theme_classic() +
  annotate("text", x=5.8, y=9, label= label_text) +
  leg

以上代码画出来的图如下: Untitled

其中各部分的解释如下

leg <- theme(title=element_text(size=15), 
             axis.text.x=element_text(size=14),
             axis.text.y=element_text(size=14),
             legend.text=element_text(size=14)) # 用于指定字体大小等,可以先忽略
label_text <- paste0("r = ", round(cor(subdata$Na,subdata$K),2)) # 用于计算相关系数r的值,并处理成标在图上的「r = xxx」的文本
library(ggplot2) # 用ggplot2包画图
ggplot(subdata, aes(x = log(Na), y = log(K))) + #指定画图的数据subdata,在aes(x = ,y = )中指定横纵坐标轴
  geom_point(size = 2,color = "#31705a") + #绘制散点部分,点的大小为2,颜色为浅绿色
  stat_smooth(method = "lm", color = "#31705a")+ #绘制拟合线部分,method = "lm" 使用线性拟合,颜色同前
  theme_classic() + # 使用ggplot的classic画图主题,是个只显示横纵坐标轴的主题
  annotate("text", x=5.8, y=9, label= label_text) + # 添加上文字标注,类型是"text",位置在x=5.8,y=9
  leg # 添加之前指定的字体大小部分,不关键