I am dealing with a dataset which is as follows
Age = sample(10:99, 50, replace=T)
Level = sample( LETTERS[1:4], 50, replace=TRUE )
df = as.data.frame(cbind(Age, Level))
This is my boxplot with jitters for the variable Age
library(plotly)
plot_ly(y = ~df$Age, type = "box", boxpoints = "all", jitter = 0.3,
pointpos = -1.8)
My question is, how do i color the jitter points on the left differently based on the level variables? Right now there are four levels in my dataset , A, B, C, D. Points corresponding to level A should be of certain color, points corresponding to level B should be in different color so on.
I tried
plot_ly(y = ~df$Age, type = "box", boxpoints = "all", jitter = 0.3, color = ~df$Level,pointpos = -1.8)
This is giving me four different boxplots. My goal is just one boxplot with the jitters colored based on the level variable. So any suggestions or help is much appreciated.