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

推荐订阅源

博客园 - 【当耐特】
罗磊的独立博客
J
Java Code Geeks
博客园_首页
量子位
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
Cloudbric
Cloudbric
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
IT之家
IT之家
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
爱范儿
爱范儿
月光博客
月光博客
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
C
CERT Recently Published Vulnerability Notes
S
Schneier on Security
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 司徒正美
The Cloudflare Blog
G
GRAHAM CLULEY
I
Intezer
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
Engineering at Meta
Engineering at Meta

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 # 添加之前指定的字体大小部分,不关键