我正在处理一个数据集,如下所示
Age = sample(10:99, 50, replace=T)
Level = sample( LETTERS[1:4], 50, replace=TRUE )
df = as.data.frame(cbind(Age, Level))
这是我的箱线图,其中包含变量的抖动Age
library(plotly)
plot_ly(y = ~df$Age, type = "box", boxpoints = "all", jitter = 0.3,
pointpos = -1.8)
我的问题是,如何根据级别变量对左侧的抖动点进行不同的着色?现在我的数据集中有四个级别,A、B、C、D。对应于级别 A 的点应该具有某种颜色,对应于级别 B 的点应该具有不同的颜色,依此类推。
I tried
plot_ly(y = ~df$Age, type = "box", boxpoints = "all", jitter = 0.3, color = ~df$Level,pointpos = -1.8)
这给了我四个不同的箱线图。我的目标只是一张箱线图,其中抖动根据级别变量着色。因此,非常感谢任何建议或帮助。