【问题标题】:Change the color of a confidence interval band?更改置信区间带的颜色?
【发布时间】:2021-06-11 12:52:27
【问题描述】:

我正在使用 blandr 包制作 Bland & Altman 图,置信区间肯定是我想要绘制的:

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

我希望更改置信区间的颜色。据我所知,它们不会对填充颜色的任何变化做出反应。我能做什么?

【问题讨论】:

  • 这通常是高级函数的问题。颜色是硬编码在函数blandr.plot.ggplot 中的——你可以在那里改变它。或者也许自己计算统计数据并使用更多较低级别的 ggplot2

标签: r ggplot2 color-scheme


【解决方案1】:

blandr 创建一个 ggplot 对象,因此您可以使用ggplot_build 方法修改颜色。

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))

reprex package (v2.0.0) 于 2021 年 6 月 11 日创建

【讨论】:

  • 太棒了!为了将来参考,可以使用as_ggplot()gtable 再次变为ggplot obj,这是我需要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-10
  • 1970-01-01
  • 2019-03-23
  • 2017-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多