前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ggplot2绘图基础功不扎实?看完这5个资源

ggplot2绘图基础功不扎实?看完这5个资源

作者头像
生信菜鸟团
发布2020-05-19 23:57:28
1.2K0
发布2020-05-19 23:57:28
举报
文章被收录于专栏:生信菜鸟团生信菜鸟团

基本上每个研究的发表,都伴随着精美的图表,比如:

能制作这样图表的工具很多, 我比较喜欢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 Wickham

This 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语言,知识点路线图如下:

  • 了解常量和变量概念
  • 加减乘除等运算(计算器)
  • 多种数据类型(数值,字符,逻辑,因子)
  • 多种数据结构(向量,矩阵,数组,数据框,列表)
  • 文件读取和写出
  • 简单统计可视化
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-05-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信菜鸟团 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ggplot2作者亲自写的书
    • Getting started
      • Introduction
        • III The Grammar
          • IV Extending ggplot2
          • 知识点参考卡片(速记表,小抄)
          • sthda网站的ggplot核心图表示例
          • 绘图菜谱
          • 最后一个是 https://stackoverflow.com/
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档