R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

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.

Data Processing for Plot 1 - Heatmap R Code

Loading required package:

library(datasets)
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(reshape2)

Loading the airquality dataset

data("airquality")

Convert Month to factor

airquality$Month = as.factor(airquality$Month)

Extract Ozone, Month and Day columns

ozone_daily = airquality[, c(1, 5, 6)]

Convert Long format to Wide for input to Heatmap

ozone_daily = dcast(ozone_daily, Day ~ Month, value.var = "Ozone")

Convert to Matrix

ozone_daily = as.matrix(ozone_daily[, -1])
colnames(ozone_daily) = c("May", "June", "July", "August", "September")

Plotly command

plot_ly(z = ozone_daily, colorscale = "Hot", x = colnames(ozone_daily), 
    type = "heatmap", colorbar = list(title = "Ozone Levels (parts per billion)")) %>% 
    layout(title = "Daily Ozone Levels in New York, May to September 1973", 
        xaxis = list(title = "Month"), yaxis = list(title = "Day"))

Data Processing for Plot 2 : Time-Series Chart R Code

Loading required package:

library(datasets)
library(plotly)

Load the population dataset

data(uspop)

Plotly Command

plot_ly(x = ~time(uspop), y = ~uspop, type = "scatter", mode = "lines") %>% 
    layout(title = "U.S. Population in millions for the period 1790-1970", 
        xaxis = list(title = "Year"), yaxis = list(title = "U.S. Population (millions)"))