I have a data frame with several groups values, and I would like to have a boxplot per category (drawn together). I want to have each boxplot with a different width, based
There is the possibility to weight each box plot via the weight aesthetics.
You need to have the quantreg package installed to use this. I guess you can just provide your function in there, I used for demonstration an exponent of the drivesCount column. So you need to adapt this a little.
install.packages("quantreg")
ggplot(Data, aes(x=roadType, y=happyPercentage)) +
geom_boxplot(varwidth = TRUE, alpha=0.2, aes(weight=drivesCount^10)) +
theme(legend.position="none") +
labs(x = "Road Type", y = "Happy People Percent") +
theme(plot.title = element_text(hjust = 0.5))