Joanna Zhao’s and Jenny Bryan’s R graph catalog is meant to be a complement to the physical book,Creating More Effective Graphs, but it’s a really nice gallery in its own right. The catalog shows a series of different data visualizations, all made with R and ggplot2. Click on any of the plots and you get the R code necessary to generate the data and produce the plot.
 
You can use the panel on the left to filter by plot type, graphical elements, or the chapter of the book if you’re actually using it. All of the code and data used for this website is open-source, in this GitHub repository. Here's an example for plotting population demographic data by county that uses faceting to create small multiples:
library(ggplot2)
library(reshape2)
library(grid) this_base = "fig08-15_population-data-by-county" my_data = data.frame(
Race = c("White", "Latino", "Black", "Asian American", "All Others"),
Bronx = c(194000, 645000, 415000, 38000, 40000),
Kings = c(855000, 488000, 845000, 184000, 93000),
New.York = c(703000, 418000, 233000, 143000, 39000),
Queens = c(733000, 556000, 420000, 392000, 128000),
Richmond = c(317000, 54000, 40000, 24000, 9000),
Nassau = c(986000, 133000, 129000, 62000, 24000),
Suffolk = c(1118000, 149000, 92000, 34000, 26000),
Westchester = c(592000, 145000, 123000, 41000, 23000),
Rockland = c(205000, 29000, 30000, 16000, 6000),
Bergen = c(638000, 91000, 43000, 94000, 18000),
Hudson = c(215000, 242000, 73000, 57000, 22000),
Passiac = c(252000, 147000, 60000, 18000, 12000)) my_data_long = melt(my_data, id = "Race",
variable.name = "county", value.name = "population") my_data_long$county = factor(
my_data_long$county, c("New.York", "Queens", "Kings", "Bronx", "Nassau",
"Suffolk", "Hudson", "Bergen", "Westchester",
"Rockland", "Richmond", "Passiac")) my_data_long$Race =
factor(my_data_long$Race,
rev(c("White", "Latino", "Black", "Asian American", "All Others"))) p = ggplot(my_data_long, aes(x = population / 1000, y = Race)) +
geom_point() +
facet_wrap(~ county, ncol = 3) +
scale_x_continuous(breaks = seq(0, 1000, 200),
labels = c(0, "", 400, "", 800, "")) +
labs(x = "Population (thousands)", y = NULL) +
ggtitle("Fig 8.15 Population Data by County") +
theme_bw() +
theme(panel.grid.major.y = element_line(colour = "grey60"),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
panel.margin = unit(0, "lines"),
plot.title = element_text(size = rel(1.1), face = "bold", vjust = 2),
strip.background = element_rect(fill = "grey80"),
axis.ticks.y = element_blank()) p ggsave(paste0(this_base, ".png"),
p, width = 6, height = 8)
 
Keep in mind not all of these visualizations are recommended. You’ll find pie charts, ugly grouped bar charts, and other plots for which I can’t think of any sensible name. Just because you can use the add_cat() function from Hilary Parker’s cats package to fetch a random cat picture from the internet and create an annotation_raster layer to add to your ggplot2 plot, doesn’t necessarily mean you shoulddo such a thing for a publication-quality figure. But if you ever needed to know how, this R graph catalog can help you out.
library(ggplot2)

this_base = "0002_add-background-with-cats-package"

## devtools::install_github("hilaryparker/cats")
library(cats)
## library(help = "cats") p = ggplot(mpg, aes(cty, hwy)) +
add_cat() +
geom_point()
p ggsave(paste0(this_base, ".png"), p, width = 6, height = 5)

R + ggplot2 Graph Catalog(转)的更多相关文章

  1. R ggplot2 线性回归

    摘自  http://f.dataguru.cn/thread-278300-1-1.html library(ggplot2) x=1:10y=rnorm(10)a=data.frame(x= x, ...

  2. R & ggplot2 & Excel绘图(直方图/经验分布图/QQ图/茎叶图/箱线图)实例

    持续更新~ 散点图 条形图 文氏图 饼图 盒型图 频率直方图 热图 PCA图 3D图 火山图 分面图 分面制作小多组图 地图 练习数据: year count china Ame jap '12 2. ...

  3. R:ggplot2数据可视化——进阶(1)

    ,分为三个部分,此篇为Part1,推荐学习一些基础知识后阅读~ Part 1: Introduction to ggplot2, 覆盖构建简单图表并进行修饰的基础知识 Part 2: Customiz ...

  4. R:ggplot2数据可视化——基础知识

    1 安装 # 获取ggplot2 最容易的就是下载整个tidyverse: install.packages("tidyverse") # 也可以选择只下载ggplot2: ins ...

  5. R:ggplot2数据可视化——进阶(3)

    Part 3: Top 50 ggplot2 Visualizations - The Master List, 结合进阶1.2内容构建图形 有效的图形是: 不扭曲事实 传递正确的信息 简洁优雅 美观 ...

  6. R:ggplot2数据可视化——进阶(2)

    Part 2: Customizing the Look and Feel, 更高级的自定义化,比如说操作图例.注记.多图布局等  # Setup options(scipen=999) librar ...

  7. R ggplot2 翻转坐标

    p <- ggplot(mpg, aes(class, hwy)) p + geom_boxplot() p + geom_boxplot() + coord_flip()

  8. R ggplot2 改变颜色

    p<-ggplot(iris,aes(Petal.Length,Petal.Width,color=Species))+geom_point()cols=c("red",&q ...

  9. R语言中文社区历史文章整理(类型篇)

    R语言中文社区历史文章整理(类型篇)   R包: R语言交互式绘制杭州市地图:leafletCN包简介 clickpaste包介绍 igraph包快速上手 jiebaR,从入门到喜欢 Catterpl ...

随机推荐

  1. 嵌入javascript脚本的位置

    JavaScript脚本可以放在HTML文档任何需要的位置.一般来说,可以在<head>与</head>.<body>与</body>标记对之间按需要放 ...

  2. webx request注入单例增强实现

    由于在spring中request对象的scope限制导致了request对象无法直接注入到单例bean中,所以webx对其进行了增强实现,达到单例注入的目的. 实现原理大致如下: 1 启动时注册全局 ...

  3. sql连接查询中on筛选与where筛选的区别

    sql查询这个东西, 要说它简单, 可以很简单, 通常情况下只需使用增删查改配合编程语言的逻辑表达能力,就能实现所有功能. 但是增删查改并不能代表sql语句的所有, 完整的sql功能会另人望而生畏. ...

  4. Unity 类似FingerGestures 的相机跟随功能

    本文原创,转载请注明出处:http://www.cnblogs.com/AdvancePikachu/p/6555188.html 最近在做一款VR项目,有一个查看功能,分为自由查看和跟随查看. 自由 ...

  5. java复习(4)---数字处理类

    java本身自带一些封装好的类方便数字问题的处理,review下方便以后使用 DecimalFormat类 可格式化数字格式,控制输出格式 Math类 提供三角函数.指数函数.取整函数.最大最小函数. ...

  6. HTTP 协议

    HTTP 协议对应 Web 开发者来说都必须要了解的,无论技术背景或首选编程语言是什么,"请求-响应" 对话是驱动 Web 上通信的基础. HTTP 概述 HTTP 协议是 Hyp ...

  7. IE和其他浏览器用JS新窗口打开的问题

    Chrome中 window.open(pageURL,name,parameters) pageURL 为子窗口路径 name 为子窗口句柄 parameters 为窗口参数(各参数用逗号分隔) 例 ...

  8. Python-一些实用的函数

    一,返回值为bool类型的函数 1.any()函数 any(iterable)->bool 当迭代器中有一个是Ture,则返回Ture:若interable=NUll,则返回False. > ...

  9. C#如何向word文档插入一个新段落及隐藏段落

    编辑Word文档时,我们有时会突然想增加一段新内容:而将word文档给他人浏览时,有些信息我们是不想让他人看到的.那么如何运用C#编程的方式巧妙地插入或隐藏段落呢?本文将与大家分享一种向Word文档插 ...

  10. DFB系列 之 SetCooperativeLevel协作级别

    1. 函数原型解析 函数声明 function SetCooperativeLevel(hWnd: HWND; dwFlags: DWORD): HResult; stdcall; 设置指定的IDir ...