26/11/2020

Overview

This presentation provides a subtle use of plotly and R markdown presentations to show a formatted dataset into a graph.

Loading packages

It is necessary to load the packages that are going to be used. As the assignment required, there should be some plot made with the plotly. For the dataset, trees will be used as the information source to make the plot.

library(plotly)
data("trees")

Knowing the content of the dataset

To know what variables need to be plotted to show any kind of information, first the dataset has to be seen to get what variables has and the type of values that are contained.

head(trees)
##   Girth Height Volume
## 1   8.3     70   10.3
## 2   8.6     65   10.3
## 3   8.8     63   10.2
## 4  10.5     72   16.4
## 5  10.7     81   18.8
## 6  10.8     83   19.7

Coding the plot

For this step, two variables will be plotted, height and volume. This will try to show how the height would affect the volume of a tree. There will also be a linear model to get a standard behavior of the expected volume a tree would have according of how tall it is.

plot_ly(trees, x = ~Height, y = ~Volume, type = "scatter", mode = "markers") %>% 
    add_lines(x = ~Height, y = fitted(lm(Volume ~ Height, data = trees))) %>% 
    layout(showlegend = FALSE)

Presenting the plot

Thanks