It is school holidays and I have mostly been taking kids to swim lessons and the beach this week 😄.
But I thought it might be useful to show you a interactive visualisation tool called plotly()
that Kate and I discovered last week.
One of the great things about R is that you can visualise individual trials and/or participants, but when you do that you can sometimes find values that stick out. They might be errors or outliers- to determine that it is helpful to be able to access more information about the weird points. That is where plotly comes in.
The plotly package can be used to visualise data outside of ggplot (https://plotly.com/r/) but you can also plotlify your ggplot using the ggplotly()
function. Lets make a penguin plot to illustrate.
library(tidyverse)
library(palmerpenguins)
library(plotly)
penguins <- penguins
Here I am plotting body mass by bill depth, differentiating species by colour, add shape to differentiate sex and labels to code for island. And saving the plot as an object called p1.
standard ggplot…
p1 <- penguins %>%
ggplot(aes(x= body_mass_g, y = bill_depth_mm, colour = species, shape = sex, label = island)) +
geom_point() +
ggeasy::easy_remove_legend()
p1
Then run the ggplotly on the plot. Now you can hover over any point and get information about the values, species and sex.
plotly1 <- ggplotly(p1)
plotly1
Hover over the points you are interested in- FUN!