library(tidyverse)
library(plotly)
library(ggplot2)
library(scales)
library(crosstable)
# Load data here
cars <- ggplot(mtcars2, aes(x = mpg, y = disp)) + geom_point(aes(color=hp,text=model)) +
labs(x= "Miles per gallon (MPG)", y = "Displacement (Cu in)", color="HP") + theme_minimal()
interactive_plot <- ggplotly(cars, tooltip="text")
interactive_plot
htmlwidgets::saveWidget(interactive_plot, "cars_plot.html")
cars2 <- ggplot(mtcars2, aes(x = mpg, y = cyl)) + geom_point(aes(color=hp,text=model)) +
labs(x= "Miles per gallon (MPG)", y = "# of Cylinders", color="HP") + theme_minimal()
interactive_plot2 <- ggplotly(cars2, tooltip="text")
interactive_plot2
htmlwidgets::saveWidget(interactive_plot2, "cars_plot2.html")
cars3 <- ggplot(mtcars2, aes(x = mpg, y = cyl)) + geom_point(aes(color=wt,text=model)) +
labs(x= "Horsepower (HP)", y = "# of Cylinders", color="Weight (1000lbs)") + theme_minimal()
interactive_plot3 <- ggplotly(cars3, tooltip="text")
interactive_plot3
htmlwidgets::saveWidget(interactive_plot3, "cars_plot3.html")
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!