kassambara / ggpubr

'ggplot2' Based Publication Ready Plots
https://rpkgs.datanovia.com/ggpubr/
1.14k stars 165 forks source link

Change "size" separately in ggbarplot for point and mean_se #576

Open SeadonXing opened 1 year ago

SeadonXing commented 1 year ago

Thank you for this cool tool.

I want to change the size of point and the thicknes of mean_se in ggbarplot together. But I can't assign two "size" parameter in add.params. My question is how can I change the size of point and the thicknes of mean_se in ggbarplot at the same time by using same parameter "size"?

Example

library(ggpubr) df1 = data.frame("group1" = rnorm(24, 20, sd = 2), "group2" = rnorm(24, 30), "group3" = rnorm(24, 40) )

df1[1:6,] = df1[1:6,]/2 df1[7:12,] = df1[1:6,]/3

df1$Treatment = rep(c(paste("Tr", 1:3, sep = "")), each = 8)

dfm = melt(df1, id.vars = "Treatment")

Too thick for error bar

ggbarplot(dfm, x = "variable", y = "value", add = c("mean_sd", "point"), color = "Treatment", fill = "Treatment", alpha = 0.5, position = position_dodge(), add.params = list(color = "Treatment", size=3))

Too small for point

ggbarplot(dfm, x = "variable", y = "value", add = c("mean_sd", "point"), color = "Treatment", fill = "Treatment", alpha = 0.5, position = position_dodge(), add.params = list(color = "Treatment", size=0.5))

drock2495 commented 1 week ago

Hi,

I was also trying to find a way to change points and outlines independently as it means you cannot have control over point size in plots with bars (or boxes) displaying error bars and points.

I found a workaround to this problem using your example provided. Turn off points in the add parameter of ggbarplot() and insert them manually using geom_point() instead. Then you can set the size parameter there.

dfm %>% ggbarplot(x = "variable", y = "value", add = c("mean_sd"), color = "Treatment", fill = "Treatment", alpha = 0.5, position = position_dodge()) + geom_point(aes(fill=Treatment,col=Treatment),position = position_dodge(0.8), size=3)