Task 1: Reflection

Using plotly, for the second task, I was able to create a plot that provides more informaiton the further you look into the numbers. Using plotly, allowed me to hover over the label and specify the information for each car. Something that was helpful for me to add was the name of the car, which could be used to see if specific brands might be heavier or lighter. Using the flexboard, I was able to create a dash board on car data. It allows me to compare different aspects of the cars next to each other, For example, I was able to see that the heavier a car is or the more horse power a car has, the less miles per gallon they get. Cars with higher horse power also have more cylinders. Overall, using these two tools made it easier to interact with and get a greater understanding of the data.

Task 2: Interactive plots

library(tidyverse)
library(plotly)
# Load data here

Do the following:

  1. Make a plot. Any kind of plot will do (though it might be easiest to work with geom_point()).
data("mtcars")
head(mtcars)
# make a cars frame
 
mtcars$car <- rownames(mtcars)

# create a plot

p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(am, labels = c("Automatic", "Manual")),
                        #set the text values that will be used for plotly
                        text = paste("Car:", car, "\n",
                          "Weight (1000 lbs):", wt,
                                     "<br>Miles per Gallon (mpg):", mpg,
                                     "<br>Transmission:", ifelse(am == 0, "Automatic", "Manual")))) +
  geom_point(alpha = 1) +
  labs(title = "Miles per Gallon vs. Weight",
       x = "Weight (1000 lbs)",
       y = "Miles per Gallon (mpg)",
       color = "Transmission") +
  scale_color_manual(values = c("blue", "red"))

mpg_plot = ggplotly(p, tooltip = "text")

mpg_plot
htmlwidgets::saveWidget(mpg_plot, "task2.html")