Creating interactive plots with ggplotly
Metabolites and lipids descriptive statistical analysis in R
# Changing ggplot2 box plots with dots into interactive plot:
# Calling libraries:
library(plotly)
library(tidyverse)
# Consulting the documentation:
?ggplotly()
# Create 'data.long' tibble:
data.long <- data %>%
select(`Label`,
`SM 39:1;O2`,
`SM 40:1;O2`,
`SM 41:1;O2`,
`SM 42:1;O2`) %>%
pivot_longer(cols = `SM 39:1;O2`:`SM 42:1;O2`,
names_to = 'Lipids',
values_to = 'Concentrations')
# Creating a plot:
box.plots <-
ggplot(data.long, aes(x = `Label`,
y = `Concentrations`,
fill = `Label`)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitter(width = 0.05), shape = 21) +
scale_fill_manual(values = c('royalblue', 'orange', 'red2')) +
facet_grid(. ~ Lipids) +
theme_classic() +
theme(strip.placement = "outside",
strip.background = element_blank(),
panel.border = element_blank(),
panel.spacing.x = unit(0, 'cm'))
# Changing the plot into an interactive version:
ggplotly(box.plots)

Last updated