when the standard error bar is overlapped with the jitter, I want to show the error bar by changing the color of it.
However, when I added add.params = list(color = "black")
, all additional components were changed to black.
How can I only change the color of the error bar?
# original code: https://rpkgs.datanovia.com/ggpubr/reference/ggbarplot.html
library(ggpubr)
ggbarplot(ToothGrowth, x = "dose", y = "len", color = "supp",
add = c("mean_se", 'jitter'), palette = c("#00AFBB", "#E7B800"),
position = position_dodge(0.8))
One option to fix that would be to manipulate the ggplot2
object, i.e. for the example plot the error bars are added as the third layer:
library(ggpubr)
#> Loading required package: ggplot2
p <- ggbarplot(ToothGrowth,
x = "dose", y = "len", color = "supp",
add = c("mean_se", "jitter"), palette = c("#00AFBB", "#E7B800"),
position = position_dodge(0.8)
)
p$layers
#> [[1]]
#> mapping: colour = ~supp
#> geom_bar: just = 0.5, width = 0.7, na.rm = FALSE, orientation = NA
#> stat_identity: na.rm = FALSE
#> position_dodge
#>
#> [[2]]
#> mapping: colour = ~supp
#> geom_point: na.rm = FALSE
#> stat_identity: na.rm = FALSE
#> position_jitterdodge
#>
#> [[3]]
#> mapping: colour = ~supp, group = ~supp
#> geom_errorbar: na.rm = FALSE, orientation = NA, width = 0.1
#> stat_summary: fun.data = mean_se_, fun = NULL, fun.max = NULL, fun.min = NULL, fun.args = list(error.limit = "both"), na.rm = FALSE, orientation = NA
#> position_dodge
Based on this information we can set the colour
parameter to black
for the error bars only like so:
p$layers[[3]]$aes_params$colour <- "black"
p