The Interactive Plots presented in this Assignment are as follows - 1. Quarterly UK gas consumption over a certain period 2. Violent Crime Rates by US State: Scatter plot describe the relation between murder and assault 3. Predict Chicken Weight using Diet and Time as Regressor
A quarterly time series of length 108. Start from 1960Q1 to 1986Q4, in millions of therms.
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
data("UKgas")
plot_ly(x=~time(UKgas),y=~UKgas,type="scatter",mode="lines") %>% layout(title = "UK Quarterly Gas Consumption", xaxis = list(title = "Year"),yaxis = list(title = "Gas Consumption"))
This data set contains statistics, in arrests per 100,000 residents for assault, murder, and rape in each of the 50 US states in 1973. Also given is the percent of the population living in urban areas.
data("USArrests")
USArrests %>% plot_ly(x = USArrests$Murder, y = USArrests$Assault, type = "scatter")%>% layout(title = "Murder vs Assault in US", xaxis = list(title = "Murder"),yaxis = list(title = "Assault"))
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
data("ChickWeight")
fit <- lm(weight ~ Diet+Time, ChickWeight)
diet <- unique(ChickWeight$Diet)
time <- unique(ChickWeight$Time)
grid <- with(ChickWeight, expand.grid(time, diet))
d <- setNames(data.frame(grid), c("Time", "Diet"))
vals <- predict(fit, newdata = d)
m <- matrix(vals, nrow = length(unique(d$Time)), ncol = length(unique(d$Diet)))
plot_ly() %>%
add_surface(x = ~time, y = ~diet, z = ~m)