January 13, 2019

Instructions

Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly.

Miles per gallon by number of cylinders

We will use mtcars dataset to analyse average miles per gallon (mpg) of cars with different number of cylinders.

Loading the dataset and averaging miles per gallon on cylinders.

data(mtcars)
library(dplyr)
library(plotly)
library(ggplot2)

df <- aggregate(mtcars, FUN = mean, by = list(mtcars$cyl))
df <- select(df, cyl, mpg)
df
##   cyl      mpg
## 1   4 26.66364
## 2   6 19.74286
## 3   8 15.10000

Histogram of MPG on Cylinders using Plotly

Appendix

Code used to generate plotly histogram of MPG on Cylinders.

g <- ggplot(mtcars, aes(mpg, fill = (as.factor(cyl)))) +
  geom_histogram(binwidth = 1, position = "identity") + 
  ggtitle("Interactive Histogram of mpg on cyl")
ggplotly(g)