2023-07-28

Synopsis

Following instructions have been given for the assignment -

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

The Interactive Plots presented in this Assignment are as follows -

  1. A Heatmap depicting the Daily Ozone Levels in New York over a period of 5 months (May to September 1973).
  2. A Time-Series chart of the Population of the United States (in millions) for the period 1790-1970.

Data Processing for Plot 1 : Heatmap R Code

library(datasets);library(plotly);library(reshape2)
data("airquality") ## Load the airquality dataset

airquality$Month=as.factor(airquality$Month) ## Convert Month to factor
ozone_daily=airquality[,c(1,5,6)] ## Extract Ozone, Month and Day columns

## Convert Long format to Wide for input to Heatmap
ozone_daily=dcast(ozone_daily,Day~Month,value.var = "Ozone") 
ozone_daily=as.matrix(ozone_daily[,-1]) ## Convert to Matrix
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"))

Plotly - Interactive Plot 1: Heatmap

Plot 2 : Time-Series Chart R Code

library(datasets)
library(plotly)
data(uspop) ## Load the data set that gives the population of the United States 
## (in millions) as recorded by the decennial census for the period 1790–1970.

## 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)"))

Plotly - Interactive Plot 2: Time-Series Chart

Thank You!