Skip to content

Instantly share code, notes, and snippets.

View mjahanshahi's full-sized avatar

Maryam mjahanshahi

View GitHub Profile
# Takes an ordered vector of numeric values and returns a small bar chart made
# out of Unicode block elements. Works well inside dplyr mutate() or summarise()
# calls on grouped data frames.
sparkbar <- function(values) {
span <- max(values) - min(values)
if(span > 0 & !is.na(span)) {
steps <- round(values / (span / 7))
blocks <- c('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '')
library(grid)
library(hrbrthemes)
library(tidyverse)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
labs(title = "A Title", subtitle = "A Subtitle") +
theme_ipsum_rc(grid="XY") -> gg
gb <- ggplot_build(gg)