Put your reflection here
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:
Make a plot. Any kind of plot will do (though it might be easiest to work with geom_point()).
Make the plot interactive with ggplotly().
Make sure the hovering tooltip is more informative than the default.
Good luck and have fun!
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 <- ggplotly(plot, tooltip = "text")
interactive
htmlwidgets::saveWidget(myplot, "myplot.html")
htmlwidgets::saveWidget(interactive, "text_interactiveplot.html")