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_pal()
scales::show_col(ptt_pal(6))
vnk_pal()
scales::show_col(vnk_pal(4))
scale_colour_ptt()
and scale_fill_ptt()
p <- ggplot(pdat, aes(x = date, y = values, colour = vars)) + geom_line() p p + scale_colour_ptt()
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.
p + the_legend_bot() p + the_title_blank() p + the_title_blank(c("x", "l")) p + the_x45()
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)
p + geom_h0()
grid_arrange_shared_legend(p, p + geom_h0(), ncol = 2)
p + scale_y_continuous(breaks = extra_breaks(17))
halfq_shift()
to shift time a half quarter in quarter chartsggsave_twitter()
to save plots for twitter.ggsave_blog()
to save plots for blog text.ggsave_ppt_half()
to save plots for ppt-slide, a half-slide plot.translate_plot()
to translate all text in a plot.p <- ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point() + labs(title = "Test plot") translation <- c("Test plot" = "Testikuvio", wt = "Paino", mpg = "Mailia per gallona") p2 <- translate_plot(p, translation) p p2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.