ggptt
July 25, 2018 ยท View on GitHub
ggptt
A collection of ggplot2 themes and functions for use in PTT.
installation
Install from github:
# install.packages("devtools")
devtools::install_github("pttry/ggptt")
Introduction to ggptt
Prepartions for introduction:
# Install and load packages
# install.packages(c("ggptt", "dplyr", "tidyr", "scales"))
library(ggptt)
library(dplyr)
# Clear possible settings
unset_ptt()
# data for examples
pdat <- economics %>%
select(date, psavert, uempmed) %>%
tidyr::gather(vars, values, -date)
ggptt will also load ggplot2.
PTT colours
PTT colours: ptt_pal()
scales::show_col(ptt_pal(6))

VNK: vnk_pal()
scales::show_col(vnk_pal(4))

PTT scales
scale_colour_ptt() and scale_fill_ptt()
p <- ggplot(pdat, aes(x = date, y = values, colour = vars)) +
geom_line()
p

p + scale_colour_ptt()

PTT theme
p + theme_ptt()

set_ptt() sets PTT theme and colours. unset_ptt() could be used to undo ggptt settings.
set_ptt()
p

Also theme_map() for maps.
"the"-theme elemets
p + the_legend_bot()

p + the_title_blank()

p + the_title_blank(c("x", "l"))

p + the_x45()

scale formaters
p + scale_x_date(labels = no_century)

# Percents
pdat2 <- pdat %>% mutate(values = values/100)
p %+% pdat2 + scale_y_continuous(labels = percent_comma)

# comma
p %+% pdat2 + scale_y_continuous(labels = deci_comma)

Extra geoms
Horizontal 0-line
p + geom_h0()

Share a legend
grid_arrange_shared_legend(p, p + geom_h0(), ncol = 2)

Add extra breaks to a continuous scale
p + scale_y_continuous(breaks = extra_breaks(17))
