John Marquess Messing around with data

First post using R Markdown with jekyll and knitr

I wanted to set up a website to reproduce data analysis examples and graphical output. I have been using RStudio for a while and was looking for a way to publish R Markdown scripts directly to the web.

I found a few sites that provided instructions to do this, Jerid Francom, Jason Bryer, Andrew Brooks,and Jon Zelner. I went with the process described in the latter as it was the easiest to follow. It also uses the lanyon theme that I had already deployed.

Anyway, there is no point repeating the process here. If you have installed jekyll on your local machine just follow Jon Zelner’s instructions and it will look like this site.

Here is some test code written in an R Markdown file with the resulting output. It is code used in the Udacity - Data Analysis with R course. It produces a scatter plot of the cube root of diamond price by diamond carat. (Messages and warnings are supressed.)

Load in the required libraries.


Define a cube root function to transform the data

cuberoot_trans = function(){
            transform = function(x) x ^ (1/3),
            inverse = function(x) x^3)

Produce the plot.

ggplot(aes(x = carat, y = price, color=clarity), data = diamonds) + 
  geom_point(alpha = 0.8, size = 2, position = 'jitter') +
  scale_color_brewer(type = 'div',
    guide = guide_legend(title = 'Clarity', reverse = T,
    override.aes = list(alpha = 1, size = 2))) +  
  scale_x_continuous(trans = cuberoot_trans(), limits = c(0.2, 3),
    breaks = c(0.2, 0.5, 1, 2, 3)) + 
  scale_y_continuous(trans = log10_trans(), limits = c(350, 15000),
    breaks = c(350, 1000, 5000, 10000, 15000)) +
  ggtitle('Price (log10) by Cube-Root of Carat and Clarity')  +