admin管理员组文章数量:1183725
I am using dwplot to plot multiple coefficients across multiple models. p <- dwplot(list(mod1976,mod1980,mod1984))
The plot outputs coefficients colored by model. I want to color the coefficients so that those that are positive and significant are green, negative and significant are red, and all others are grey.
Is this possible?
I am using dwplot to plot multiple coefficients across multiple models. p <- dwplot(list(mod1976,mod1980,mod1984))
The plot outputs coefficients colored by model. I want to color the coefficients so that those that are positive and significant are green, negative and significant are red, and all others are grey.
Is this possible?
Share Improve this question asked Jan 26 at 18:02 michael josephmichael joseph 595 bronze badges1 Answer
Reset to default 1This was a little harder than I thought; I couldn't figure out how to override dwplot
's colour mapping, but with slightly more effort you can draw your own plot matching the one from dwplot
, with more control.
set up example
library(broom)
library(dplyr)
library(dotwhisker)
respvars <- c("mpg", "hp", "wt")
names(respvars) <- respvars ## for .id in map_dfr
predvars <- setdiff(names(mtcars), respvars),
ms <- as.data.frame(scale(mtcars))
mm_list <- purrr::map(respvars,
~ lm(reformulate(predvars, response = .x), data = ms))
construct data frame with estimate/CI/significance info
mm_pars <- mm_list |>
purrr::map_dfr(tidy, .id = "response", conf.int = TRUE) |>
dplyr::filter(term != "(Intercept)") |>
mutate(cat = ifelse(p.value > 0.05, "ns",
ifelse(estimate > 0, "pos", "neg")))
plot
Unsuccessful attempt to override the colour mapping:
dwplot(mm_list) + aes(shape = model, colour = cat) +
scale_colour_manual(values = c("grey", "blue", "red"))
A plot that works (these aren't exactly the colours you asked for, but that should be easy to change ...)
ggplot(mm_pars, aes(x = estimate, y = term, colour = cat,
## I'm not sure the group mapping is necessary ...
shape = response, group = response)) +
geom_pointrange(position = position_dodge(width = 0.5),
aes(xmin = conf.low, xmax = conf.high)) +
## add a reference line
geom_vline(xintercept = 0, linetype = 2) +
scale_colour_manual(values = c("grey", "blue", "red"), breaks = c("ns", "pos", "neg"))
本文标签:
版权声明:本文标题:r - Can dwplot manually set colors to allow for color variation within a coefficient group across models - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738302520a2073677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论