Little useless-useful R functions – Drawing randomly generated @Github contribution graph

Github is collecting various images on their Instagram and Twitter that looks like a contribution graph.

Well, why not create one in R with randomly generated data and the use of the ggplot library.

Run the function by yourself:

library(ggplot2)

# introduce Github colours
colours <- c("#ebedf0", "#9be9a8", "#40c463","#309b4c","#216e39")
# colours: lavender, palegreen, mediumseagreen,seagreen, forestgreen
# nof_contributions:  0, 1, 2-5, 5-10, 10+

# Generate grid on imaginary
y <- weekdays(Sys.Date()+0:6) # days
x <- paste0("W_", seq(1,52))
data <- expand.grid(X=x, Y=y)
data$cols <- sample(colours, 364, replace=TRUE)

# Contribution graph 
ggplot(data, aes(X, Y)) + 
    geom_tile(aes(fill = cols, width=0.9, height=0.9)) + 
    scale_fill_manual(values=colours) + 
  labs(title = "Your R generated contributions in past year") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
       axis.ticks.x=element_blank(),
       axis.ticks.y=element_blank(),
       legend.position = "none",
       panel.background = element_rect(fill = 'white', color = 'white')
       )

And there you go!

Jokingly: …. If you want to see the tiles, that you usually see at your local pool, run this slightly altered code:

# Generate grid
colours <- c("#ebedf0", "#9be9a8", "#40c463","#309b4c","#216e39")
y <- LETTERS[1:60] # letters
x <- seq(1,60)
data <- expand.grid(X=x, Y=y)
data$cols <- sample(colours, 3600, replace=TRUE)

ggplot(data, aes(X, Y)) + 
  geom_tile(aes(fill = cols, width=0.95, height=0.95)) + 
  scale_fill_manual(values=colours) + 
  labs(title = "Your local pool tiles") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        axis.ticks.x=element_blank(),
        axis.ticks.y=element_blank(),
        axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        legend.position = "none",
        panel.background = element_rect(fill = 'white', color = 'white')
  )

As always, code is available on Github in the same Useless_R_function repository. Check Github for future updates.

Happy R-coding, stay healthy and contribute on Github! 🙂

Tagged with: , , , ,
Posted in Uncategorized, Useless R functions
One comment on “Little useless-useful R functions – Drawing randomly generated @Github contribution graph
  1. […] Tomaz Kastrun shows off contributions: […]

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

tenbulls.co.uk

tenbulls.co.uk - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...