r语言ggplot2 多线图绘制图例_ggplot2绘图基础功不扎实?看完这5个资源

单细胞技术大热,其数据分析里面很重要的一个环节就是可视化,真的是五花八门了!我们在单细胞天地公众号分享过 几百篇单细胞CNS文章阅读笔记,大家可以看得到:
  • 单细胞助力分析靶向治疗药物性超敏反应综合征
  • 使用scHCL探索单细胞转录组细胞类型
  • 溃疡性结肠炎患者的细胞内和细胞间重排
  • 一文了解单细胞基因调控网络(GRN)
  • 胃癌前病变和早期胃癌的单细胞转录组研究
基本上每个研究的发表,都伴随着精美的图表,比如:
0e2fdf912e07cd617e075ed50518bc19.png 
能制作这样图表的工具很多, 我比较喜欢ggplot2+AI, 当然,或许有高手可以独立使用ggplot2调整全部图表细节,不过,我做不到。 我只能做到的是可以绘制出几乎全部的图表的雏形,而且我个人觉得,把ggplot2学习到这个程度就足够了。一张统计图就是从数据到几何对象(点、线、条形等)的图形属性(颜色、形状、大小等)的一个映射。
  • ✦ 数据(Data),最基础的是可视化的数据和一系列图形映射(aesthetic mappings),该映射描述了数据中的变量如何映射到可见的图形属性。
  • ✦ 几何对象(Geometric objects, geoms)代表在图中实际看到的点、线、多边形等。
  • ✦ 统计转换(Statistical trassformations, stats)是对数据进行某种汇总,例如将数据分组创建直方图,或将一个二维的关系用线性模型进行解释。
  • ✦ 标度(Scales)是将数据的取值映射到图形空间,例如用颜色、大小或形状来表示不同的取值,展现标度的常见做法是绘制图例和坐标轴。
  • ✦ 坐标系(Coordinate system, coord)描述数据是如何映射到图形所在的平面,同时提供看图所需的坐标轴和网格线。
  • ✦ 分面(faceting)如何将数据分解为子集,以及如何对子集作图并展示。
  • ✦  主题(theme)控制细节显示,例如字体大小和图形的背景色。

ggplot2作者亲自写的书

链接:https://ggplot2-book.org/facet.html书名是:ggplot2: Elegant Graphics for Data Analysis
作者:Hadley WickhamThis is the online version of work-in-progress 3rd edition of “ggplot2: elegant graphics for data analysis”虽然这本书有对应的中文译本,但是时间上相对滞后,建议直接看这个在线实时更新版本。
Getting started
  • 1 Introduction
  • 2 Getting started with ggplot2
  • 3 Frequently asked questions
  • II Toolbox
Introduction
  • 4 Individual geoms
  • 5 Collective geoms
  • 6 Statistical summaries
  • 7 Maps
  • 8 Annotations
  • 9 Arranging plots
III The Grammar
  • 10 Mastering the grammar
  • 11 Build a plot layer by layer
  • 12 Scales, axes and legends
  • 13 Coordinate systems
  • 14 Facetting
  • 15 Themes
IV Extending ggplot2
  • 16 Programming with ggplot2
  • 17 ggplot2 internals
  • 18 Writing ggplot2 extensions
  • 19 Extension Case Study: Springs, Part 1
  • References
看完你一定会觉得不虚此行!至少花十天时间哦。

知识点参考卡片(速记表,小抄)

链接:https://ggplot2.tidyverse.org/reference/内容如下:
  • Plot basics
  • Layer: geoms
  • Layer: stats
  • Layer: position adjustment
  • Layer: annotations
  • Aesthetics
  • Scales
  • Guides: axes and legends
  • Facetting
  • Facetting: labels
  • Coordinate systems
  • Themes
  • Programming with ggplot2
  • Extending ggplot2
  • Vector helpers
  • Data
  • Autoplot and fortify
读这个知识点参考卡片,可以检验你ggplot2语法的记忆程度。

sthda网站的ggplot核心图表示例

链接:http://www.sthda.com/english/wiki/ggplot2-essentials书籍本身提供售卖,价格是17欧元,不过内容都是电子化了,大家直接网页浏览,就是免费的哈!内容:
  1. qplot(): Quick plot with ggplot2
  • Scatter plots
  • Bar plot
  • Box plot, violin plot and dot plot
  • Histogram and density plots
  1. Box plots
  • Basic box plots
  • Box plot with dots
  • Change box plot colors by groups
    • Change box plot line colors
    • Change box plot fill colors
  • Change the legend position
  • Change the order of items in the legend
  • Box plot with multiple groups
  • Functions: geom_boxplot(), stat_boxplot(), stat_summary()
··· 中间省略 25个章节
  1. Rotate a plot: flip and reverse
  • Horizontal plot : coord_flip()
  • Reverse y axis
  • Functions: coord_flip(), scale_x_reverse(), scale_y_reverse()
  1. Faceting: split a plot into a matrix of panels
  • Facet with one variable
  • Facet with two variables
  • Facet scales
  • Facet labels
  • facet_wrap
  • Functions: facet_grid(), facet_wrap(), label_both(), label_bquote(), label_parsed()
内容之丰富,起码需要五天左右时间完全follow下来。还包括以下扩展包:
  • factoextra - Extract and Visualize the outputs of a multivariate analysis: PCA (Principal Component Analysis), CA (Correspondence Analysis), MCA (Multiple Correspondence Analysis) and clustering analyses.
  • easyggplot2: Perform and customize easily a plot with ggplot2: box plot, dot plot, strip chart, violin plot, histogram, density plot, scatter plot, bar plot, line plot, etc, …
  • ggplot2 - Easy way to mix multiple graphs on the same page
  • ggplot2: Correlation matrix heatmap. Functions: geom_raster() and geom_tile()
  • ggfortify: Allow ggplot2 to handle some popular R packages. These include plotting 1) Matrix; 2) Linear Model and Generalized Linear Model; 3) Time Series; 4) PCA/Clustering; 5) Survival Curve; 6) Probability distribution
  • GGally: GGally extends ggplot2 for visualizing correlation matrix, scatterplot plot matrix, survival plot and more.
  • ggRandomForests: Graphical analysis of random forests with the randomForestSRC and ggplot2 packages.
  • ggdendro: Create dendrograms and tree diagrams using ggplot2
  • ggmcmc: Tools for Analyzing MCMC Simulations from Bayesian Inference
  • ggthemes: Package with additional ggplot2 themes and scales
  • Theme used to create journal ready figures easily
ggplot2之所以备受推崇,就是因为它已经成为了一个生态,层出不穷的新奇想法会在它的基础上面生长起来。

绘图菜谱

链接:http://www.cookbook-r.com/Graphs/这个有中文翻译版本,务必直接下单购买,放在书桌旁边随时翻阅。内容:
  1. Bar and line graphs (ggplot2)
  2. Plotting means and error bars (ggplot2)
  3. Plotting distributions (ggplot2) - Histograms, density curves, boxplots
  4. Scatterplots (ggplot2)
  5. Titles (ggplot2)
  6. Axes (ggplot2) - Control axis text, labels, and grid lines.
  7. Legends (ggplot2)
  8. Lines (ggplot2) - Add lines to a graph.
  9. Facets (ggplot2) - Slice up data and graph the subsets together in a grid.
  10. Multiple graphs on one page (ggplot2)
  11. Colors (ggplot2)
学了那么多语法,就在菜谱里面把握细节吧!

最后一个是 https://stackoverflow.com/

你会发现,你想实现的各种稀奇古怪的绘图需求,只需要你能使用英文描述出来,就是能找到答案的!
  • 用谷歌搜索来使用ggplot2做可视化(上):https://mp.weixin.qq.com/s/WN4TSMNjH4b6vZgYVjaRvQ
  • 用谷歌搜索来使用ggplot2做可视化(下):https://mp.weixin.qq.com/s/_Q16zDZgCr3XoO0r3wqRkw
如果我说,全部学完,需要一年的时间,不知道你还是否愿意入坑呢?不过,如果你是R语言都没有掌握好,那么可能需要先学习我给初学者的六步系统入门R语言, 知识点路线图如下:
  • 了解常量和变量概念
  • 加减乘除等运算(计算器)
  • 多种数据类型(数值,字符,逻辑,因子)
  • 多种数据结构(向量,矩阵,数组,数据框,列表)
  • 文件读取和写出
  • 简单统计可视化
  • 无限量函数学习
文末友情宣传
强烈建议你推荐我们生信技能树给身边的 博士后以及年轻生物学PI,帮助他们多一点数据认知,让科研更上一个台阶:
  • 生信爆款入门-全球听(买一得五)(第4期),你的生物信息学入门课
  • 数据挖掘第2期(两天变三周,实力加量),医学生/临床医师首选技能提高课
  • 生信技能树的2019年终总结  ,你的生物信息学成长宝藏
  • 2020学习主旋律,B站74小时免费教学视频为你领路,还等什么,看啊!!!
468b7e5ea60996915e132078be7cf659.png 推荐 阅读 01bb488878ca3112e6bf9ec1b8df48e5.png 3d73b1d2b34f91c486273ead1ca328d7.png
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值