Fredrik Nylén
Fredrik Nylén

Reputation: 577

Change the color of a confidence interval band?

I am using the blandr package to make a Bland & Altman plots, and the confidence intervals are surely something that I want to plot:

library(blandr)
x1 <- rnorm(100);x2 <- rnorm(100,mean = 1)
blandr.draw(x1,x2, ciShading = TRUE,ciDisplay=TRUE,plotter = "ggplot")

enter image description here

I would prefer to change the color of the confidence intervals. They do not respond to any change in fill color as far as I can tell. What can I do?

Upvotes: 1

Views: 1372

Answers (1)

tjebo
tjebo

Reputation: 23737

blandr creates a ggplot object, so you can modify the colors with the ggplot_build method.

library(blandr)
library(ggplot2)
x1 <- rnorm(100);x2 <- rnorm(100,mean = 1)

p <- 
blandr.draw(x1, x2, ciShading = TRUE, ciDisplay=TRUE, plotter = "ggplot")

p_build <- ggplot_build(p)
#> Warning: Use of `plot.data$x.axis` is discouraged. Use `x.axis` instead.
#> Warning: Use of `plot.data$y.axis` is discouraged. Use `y.axis` instead.
p_build$data[[12]][["fill"]] <- "grey"
p_build$data[[13]][["fill"]] <- "steelblue"
p_build$data[[14]][["fill"]] <- "thistle"

grid::grid.draw(ggplot_gtable(p_build))

Created on 2021-06-11 by the reprex package (v2.0.0)

Upvotes: 2

Related Questions