Today I created a package for R
I created my first R package today. It was shockingly easy.
I was inspired by this post which is currently the 2nd ranked post by google when you search for "R package tutorial". Turns out that while Ms. Parker's blog post is very entertaining and inspiring, it is not the best to follow step- by-step directions. I used a few other resources here and here to finish my one-hour project.
The package I wrote is called esparkcolors and is open sourced and can be found on eSpark's github page. Just power up R from the terminal and install directly from github using devtools.
install.packages("devtools") library(devtools) devtools::install_github("espark/esparkcolors") library(esparkcolors)
This entire package is one function,
eSparkColor() and all it does it let me
load colors in a vector format for passing to ggplot or the base plotting package.
These colors are special because they conform to eSpark's branding guide.
I make a lot of plots in my job and many of them end up being seen by our clients. They need to look nice and match our keynote theme, website, or google presentation theme. These plots may end up traveling quite a bit after I've created them, so they need to be versitile. Whenever I make a plot for a presentation I use our approved seven color scheme. Sometimes I'll use shades of a color to give some more depth but seven colors is often enough.
Here's a plot I made today in ggplot.
The code I used is below, although not the data. I called my nifty eSparkColor function to get the right shade of blue and orange. That way when I put it with our keynote theme it looks great.
It was very handy and not that much work to whip together an R package for this. I'm definitely going to bundle together more of the functions that I use frequently and develop them as packages for my own ease of use.
Code to generate plot seen above:
qplot(week, Sessions, color=Discipline, data=sessions_per_week_long) + theme_bw() + theme(axis.text = element_text(size = 14), axis.title = element_text(size = 16), title = element_text(size = 20)) + ggtitle("Logins per Week") + scale_color_manual(values=c("black", eSparkColor(c("blue", "orange")))) + geom_line(lwd=1.5) + geom_hline(aes(yintercept=mean(sessions_per_week$Total)), lty=2, color = "black") + geom_hline(aes(yintercept=mean(sessions_per_week$R)), lty=2, color = eSparkColor("blue")) + geom_hline(aes(yintercept=mean(sessions_per_week$M)), lty=2, color = eSparkColor("orange")) + xlab("") + ylab("Total Logins")