Peer-graded Assignment: Week-03

R Markdown Presentation and Plotly

Instructions and Review Criteria:

Create a web page presentation using R Markdown that features a plot created with plotly package. Host your webpage on either GitHub Pages, RPubs, or NeoCities.

The evaluation rubric must contains the following two questions:

  • Does the web page feature a date and is this date less than two months before the date that you’re grading this assignment?

  • Is the web page a presentation and does it feature an interactive plot that appears to have been created with Plotly?

Write-up follow up:

I have used two sources while developing this project presenation. The first one is course instruction resources and plotly website sources. In that continuation, I have added weblink after some of the plot design.

1. Three Dimensional ‘Scatterplot3d’ with ‘airquality’ data

# all needed library
suppressMessages(library(plotly))
## Warning: package 'plotly' was built under R version 3.3.3
## Warning: package 'ggplot2' was built under R version 3.3.3
suppressMessages(library(tidyr))
## Warning: package 'tidyr' was built under R version 3.3.3
suppressMessages(library(dplyr))
## Warning: package 'dplyr' was built under R version 3.3.3
# dataset is 'airquality' here
data(airquality)

# designing the first 3-dimensional plot
tm <- plot_ly(airquality,x=~Month, y=~Temp, z=~Ozone,color=~Month, mode= "markers",type = "scatter3d") %>% layout(title = "Ozone, Temperature correlation by Month")
tm
## Warning: Ignoring 37 observations
## Warning: package 'bindrcpp' was built under R version 3.3.3

[scatterplot3d link]:https://plot.ly/r/3d-scatter-plots/

Analysis: This is a conspicuous dimension of correlation between three(Ozone,Temp and Month) variable elements.Plese left-click and rotate the whole 3-dimension on any direction you want to view critical correlation among all the variables.

2. Bubble Chart with ‘Ozone’ and ‘Solar Radiation’ on >> airquality-data

bc <- plot_ly(airquality, x=~Solar.R, y=~Ozone, type = "scatter", 
        mode='markers', size=~Month, color = 'Paired', sizes = c(10,20), marker=list(opacity =1.9, sizemode='diameter')) %>% layout(title="Ozone variation by solar radiation")

bc
## Warning: Ignoring 42 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

3. Boxplot with ‘Ozone’ emission on different months

bp <- plot_ly(airquality, y=~Ozone, color = ~as.factor(Month), type="box",boxpoints = "all", jitter = 0.4,pointpos = -1.8) %>% layout(title = "Ozone emission by month", xaxis = list(title = "Month exclusive", showgrid = F))

bp
## Warning: Ignoring 37 observations
  • Obviously, there is a correlation between between ‘Ozone’ emission and high level of ‘solar radiation’.

4. Basic 2D Histogram with ‘swiss’ data

library(plotly)
head(swiss)
##              Fertility Agriculture Examination Education Catholic
## Courtelary        80.2        17.0          15        12     9.96
## Delemont          83.1        45.1           6         9    84.84
## Franches-Mnt      92.5        39.7           5         5    93.40
## Moutier           85.8        36.5          12         7    33.77
## Neuveville        76.9        43.5          17        15     5.16
## Porrentruy        76.1        35.3           9         7    90.57
##              Infant.Mortality
## Courtelary               22.2
## Delemont                 22.2
## Franches-Mnt             20.2
## Moutier                  20.3
## Neuveville               20.6
## Porrentruy               26.6
# 2D Histogram next to a scatterplot
k <- plot_ly(swiss, x=~Agriculture, y=~Fertility)%>% layout(title="Fertility correlated Agriculture")

kp <- subplot( k %>% add_markers(alpha = 0.7),
               k %>% add_histogram2d())

kp

[2D Histogram link]: https://plot.ly/r/2D-Histogram/ [2D Histogram resoureces]: https://svi.nl/TwoChannelHistogram

5. Scatterplot with ‘mtcars’ data

suppressMessages(library(plotly))

mp <- plot_ly(data=mtcars, x=~hp, y=~mpg, type='scatter',
              mode='markers', symbol=~as.factor(cyl),
              symbols=c('x','o','circle'),
             colors =c('blue','red3','green'), marker=list(size=12)) %>% layout(title="mpg and hp in correlation of cylinder", xaxis=list(title="horsepower(hp)"), yaxis=list(title="miles per 
            gallong(mpg)"))

mp

[line-and-scatter link]: https://plot.ly/r/line-and-scatter/

Conclusion: Obviously, plotly offers an animated visualization, where each data points can be carefully tracked and representated. Plotly portrays an authentication of data points on plots. I think I like it a lot with all its limitation.