Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created July 19, 2019 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/5962498ee4b8e41b5df22125a95c338e to your computer and use it in GitHub Desktop.
Save ryanburge/5962498ee4b8e41b5df22125a95c338e to your computer and use it in GitHub Desktop.
Custom Themes
library(showtext)
theme_gg <- function(fff, base_size = 14, base_family = "font")
{
font_add_google(fff, "font")
showtext_auto()
theme_minimal() +
theme(legend.position = "none") +
theme(legend.title = element_blank()) +
theme(text=element_text(size=14, family="font"))
}
showtext_opts(dpi = 300)
## Bar Labels ####
lab_bar <- function(type, pos, sz, top = TRUE){
type <- enquo(type)
if(top == FALSE) {
geom_text(aes(y = pos, label = paste0(!! type*100, '%')), position = position_dodge(width = .9), size = sz, family = "font")
}
else{
geom_text(aes(y = !! type + pos, label = paste0(!! type*100, '%')), position = position_dodge(width = .9), size = sz, family = "font")
}
}
## Error Bars ####
error_bar <- function(wd){
if(missing(wd)){
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9))
} else{
geom_errorbar(aes(ymin=lower, ymax=upper), width=wd, position=position_dodge(.9))
}
}
## Annotates ####
add_text <- function(x, y, sz, word){
if(missing(sz)){
annotate("text", x = x, y = y, label = word, size = 6, family = "font")
}else{
annotate("text", x = x, y = y, label = word, size = sz, family = "font")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment