forked from jennybc/ggplot2-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgapminder-ggplot2-themes.r
42 lines (33 loc) · 1.27 KB
/
gapminder-ggplot2-themes.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#+ setup, include = FALSE
library(knitr)
opts_chunk$set(fig.path = 'figure/themes-')
#' Note: this HTML is made by applying `knitr::spin()` to an R script. So the
#' narrative is very minimal.
library(ggplot2)
library(ggthemes)
#' pick a way to load the data
gdURL <- "http://tiny.cc/gapminder"
gDat <- read.delim(file = gdURL)
gDat <- read.delim("gapminderDataFiveYear.tsv")
str(gDat)
#' revisit a plot from earlier
p <- ggplot(gDat, aes(x = gdpPercap, y = lifeExp))
p <- p + scale_x_log10()
p <- p + aes(color = continent) + geom_point() + geom_smooth(lwd = 3, se = FALSE)
p
#' give it a title
p + ggtitle("Life expectancy over time by continent")
#' change overall look and feel with a premade theme
p + theme_grey() # the default
#' suppress the usual grey background
p + theme_bw()
#' exploring some themes from the ggthemes package
#' https://github.com/jrnold/ggthemes
p + theme_calc() + ggtitle("ggthemes::theme_calc()")
p + theme_economist() + ggtitle("ggthemes::theme_economist()")
p + theme_economist_white() + ggtitle("ggthemes::theme_economist_white()")
p + theme_few() + ggtitle("ggthemes::theme_few()")
p + theme_gdocs() + ggtitle("ggthemes::theme_gdocs()")
p + theme_tufte() + ggtitle("ggthemes::theme_tufte()")
p + theme_wsj() + ggtitle("ggthemes::theme_wsj()")
sessionInfo()