Task 1: Reflection

Put your reflection here

Task 2: Interactive plots

library(tidyverse)
library(plotly)
library(flexdashboard)
library(htmlwidgets)

# To see all the types of datasets that R has just type in console: data()
# Load data here

data.raw <- mpg
data <- data.raw %>%
  mutate(mpg = (cty*.55)+(hwy*.45))

Do the following:

  1. Make a plot. Any kind of plot will do (though it might be easiest to work with geom_point()).

  2. Make the plot interactive with ggplotly().

  3. Make sure the hovering tooltip is more informative than the default.

Good luck and have fun!

Interactive plot with multiple texts

plot <-

ggplot(data,
       aes(displ,
           mpg))+
  
  geom_point(alpha = .5,
             aes(colour = factor(cyl),
                 shape = factor(year),
                 text = paste0(model, ": ",class)))+
  
  labs(x = "Engine displacement",
       y = "Miles per gallon", 
       colour = "",
       shape = '',
       title = "Mileage by engine displacement, cylinders, and years",
       subtitle = 'Years 1999 and 2008')+
  
  theme(plot.title = element_text(face = "bold"),
        legend.title = element_text(face = "bold"),
        panel.background = element_rect(fill = "gray97"))

myplot <-  
ggplotly(plot)

Interactive Plot with one text

interactive <- ggplotly(plot, tooltip = "text")

interactive
htmlwidgets::saveWidget(myplot, "myplot.html")
htmlwidgets::saveWidget(interactive, "text_interactiveplot.html")