Created
October 14, 2020 21:13
-
-
Save geotheory/2ad328029666dfebc9acd529474bd54b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(ggplot2) | |
gg_donut = function(x, lab, textsize = 5){ | |
ggplot() + | |
geom_rect(aes(ymax = c(100, x), ymin = 0, xmax = 4, xmin = 3.2, fill = c('A','B'))) + | |
geom_text(aes(y = 0, x = 0, label = paste0(round(x,1), '%')), size = textsize) + | |
coord_polar(theta="y") + xlim(c(0, 4)) + | |
scale_y_continuous(limits = c(0,100)) + | |
scale_fill_manual(values = c('grey80','dodgerblue2')) + | |
labs(title = lab) + | |
theme_void() + | |
theme(plot.title = element_text(hjust = 0.5)) + | |
guides(fill = 'none') | |
} | |
#' Example usage | |
#' | |
#' gg_donut(45, 'Retweets') | |
#' | |
#' if(require(patchwork)){ | |
#' gg_donut(45, 'Retweets') + gg_donut(15, 'Links') + gg_donut(100*2/3, 'Hashtags') | |
#' } | |
#' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment