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. Git版本管理荟萃

    用惯了svn,突然转到git难免有点不适,写个笔记好好备忘总结一番. 一.先看历史(imooc上的一个图): 二.git与svn GIT跟SVN一样有自己的集中式版本库或服务器.但,GIT更倾向于被使 ...

  2. javaScript 基本类型之间转换

    在Java中,基本类型之间的强制转换也不是这样的,比如,整数要转换成字符串,必须使用Integer.toString()静态方法或者String.valueOf()静态方法,把字符串转换为整数,必须使 ...

  3. Sql server DATEADD日期函数的使用

    DATEADD日期函数 DATEADD() 函数在日期中添加或减去指定的时间间隔. 日:在当前日期上加两天 , ,'2014-12-30') 月:在当前日期上加两个月 , , 年:在当前日期上加两年 ...

  4. 【转载】stm32的GPIO八种工作模式

    一.推挽输出:可以输出高.低电平,连接数字器件:推挽结构一般是指两个三极管分别受两个互补信号的控制,总是在一个三极管导通的时候另一个截止.高低电平由IC的电源决定.         推挽电路是两个参数 ...

  5. git 设置不需要输入密码, 去除 fetch / pull 代码每次都需要输入密码的烦恼

    https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受https带来的极速 设置记住密码(默认15分钟): git config --global credenti ...

  6. cas错误:org.jasig.cas.client.validation.TicketValidationException: No principal was found in the response from the CAS server.

    这个问题困扰了我好几天,最终被这个哥们解决了,具体请参考:http://www.oschina.net/question/252484_149958?sort=time

  7. OpenMP 入门教程

    前两天(其实是几个月以前了)看到了代码中有 #pragma omp parallel for 一段,感觉好像是 OpenMP,以前看到并行化的东西都是直接躲开,既然躲不开了,不妨研究一下: OpenM ...

  8. Cocos2d-x 3.2 环境搭建

    参考文章地址: 1.Cocos2d-x官方安装说明文档:http://cn.cocos2d-x.org/tutorial/show?id=781 2.CSDN博客:http://blog.csdn.n ...

  9. poj2352树状数组

    Astronomers often examine star maps where stars are represented by points on a plane and each star h ...

  10. 一个使用openGL渲染的炫丽Android动画库

    android-magic-surface-view 这是一个 android 动画特效库, 可以实现各种炫酷动画. github地址: https://github.com/gplibs/andro ...