Is there a way to change the point size by variable in ggbetweenstats?
So far, I could get this:
SNV <- c(82, 90, 93, 83, 86, 86, 70, 81, 104, 90, 86, 98, 96, 91, 87, 92, 86, 99, 79, 94, 94, 84, 99, 77, 62, 70, 66, 60, 64, 70, 75, 54, 59, 66, 59, 52, 61, 74, 67, 90, 99, 97, 85, 96, 96, 74, 89, 107, 96, 94, 104, 106, 100, 96, 100, 90, 102, 81, 104, 96, 90, 101, 78, 74, 73, 71, 67, 67, 72, 76, 56, 62, 72, 63, 62, 65, 77, 72)
Log.CPI <- c(13.52, 0.00, 16.15, 12.35, 0.00, 0.00, 4.23, 5.14, 0.00, 13.45, 9.67, 9.21, 11.38, 9.64, 18.40, 15.21, 9.88, 13.94, 0.00, 14.54, 0.00, 11.96, 15.22, 6.74, 3.69, 9.86, 4.70, 9.23, 4.57, 10.83, 6.56, 3.97, 10.16, 9.03, 4.47, 5.06, 7.47, 5.61, 4.17, 13.87, 0.00, 16.36, 11.90, 0.00, 0.00, 9.19, 9.39, 0.00, 13.55, 15.54, 10.59, 14.77, 11.39, 18.41, 15.55, 10.71, 13.96, 0.00, 14.93, 0.00, 11.98, 15.89, 9.11, 7.07, 9.88, 7.87, 9.03, 6.40, 11.10, 7.82, 5.71, 9.78, 9.77, 6.43, 5.46, 7.51, 7.82, 8.46)
Method <- rep(c("CPI_trad","CPI_new"),each=39)
df <- data.frame(SNV, Log.CPI, Method)
library(ggstatsplot)
library(tidyverse)
df$Method <- factor(df$Method, levels=c("CPI_trad", "CPI_new"))
ggbetweenstats(
plot.type = "box",
p.adjust.method = "none",
data = df,
x = Method,
y = SNV,
point.args = list(position = ggplot2::position_jitterdodge(dodge.width = 0.6), alpha
= 0.4, size = 4, stroke = 0))
I want points to inherit size from the variable "Log.CPI". Something like this in ggplot:
ggplot() +
geom_boxplot(data=df, aes(x=Method, y=SNV),
outlier.shape = NA, width=0.5) +
geom_point(data = df,
aes(x=Method, y=SNV, color = Method, size = Log.CPI),
position=position_jitter(h=0,w=0.15), alpha = 0.5) +
scale_size(breaks = c(0,4,8,12,16,20), limits = c(0,20)) +
guides(colour = guide_legend(override.aes = list(size=5))) +
theme_classic()
changing point.args = list(size = Log.CPI) in ggbetweenstats doesn’t do the trick:
point.args = list(position = ggplot2::position_jitterdodge(dodge.width = 0.6), alpha
= 0.4, size = Log.CPI, stroke = 0))