17/9/2020

Objective

This presentation (made with R Markdown in Rstudio) will use the ToothGrowth data set to draw a graph with ggplot2 and convert it to an interactive map with plotly.

R Code

library(plotly)
library(ggplot2)
data(ToothGrowth)

# Generate a ggplot graph
plot <- ggplot(ToothGrowth, aes(as.factor(dose), len)) +
        geom_boxplot(aes(fill=as.factor(dose))) + 
        facet_grid(.~supp) +
        labs (x = "Dose Amount (mg/day)",
              y = "Length of odontoblasts",
              title = "Length vs. Dose by Supplement") +
        theme(legend.position = "none")

# Convert ggplot graph to an interactive one with plotly
ggplotly(plot)

Slide with Plot