August 07, 2023

Overview

From the instructions, this time the assignment is goal to provide a presentation utilizing the plotly library and documented in using RMarkdown. For my case, I used the mtcars dataset to create an interactive plots that show different relationship between the features of the 32 automobiles:

Feature Description
mpg Miles/(US) gallon
hp Gross horsepower
cyl Number of cylinders
gear Number of forward gears

Using the mtcars Dataset in R

library(plotly)
data <- mtcars[sample(nrow(mtcars), min(250, nrow(mtcars))), 
               c("mpg", "hp", "cyl", "gear")]
summary(data)
      mpg              hp             cyl             gear      
 Min.   :10.40   Min.   : 52.0   Min.   :4.000   Min.   :3.000  
 1st Qu.:15.43   1st Qu.: 96.5   1st Qu.:4.000   1st Qu.:3.000  
 Median :19.20   Median :123.0   Median :6.000   Median :4.000  
 Mean   :20.09   Mean   :146.7   Mean   :6.188   Mean   :3.688  
 3rd Qu.:22.80   3rd Qu.:180.0   3rd Qu.:8.000   3rd Qu.:4.000  
 Max.   :33.90   Max.   :335.0   Max.   :8.000   Max.   :5.000  

Create 2D and 3D Scatter Plots

Plot2D <- plot_ly(data, x = ~mpg, y = ~hp, color = ~cyl,
        size = ~cyl, text = ~paste("Gear: ", gear))

Plot3D <- plot_ly(data, x = ~mpg, y = ~hp, z = ~gear,
        color = ~cyl, size = ~cyl, 
        text = ~paste("Gear: ", gear))

2D Scatter Plot Output

Here’s an interactive 2D scatter plot that displays the relationship between miles per gallon (mpg) and horsepower (hp) of selected cars:

3D Scatter Plot Output

Now let’s explore a 3D scatter plot that adds the number of gears (gear) as the third dimension:

Conclusion

Thank you! for joining me in this presentation. I hope you enjoyed the interactive plot created with Plotly. Feel free to explore the plot and interact with it to gain insights!