我怎么做类似的事情:

问题描述 投票:0回答:1

一些模拟数据和代码:

scale_color_manual()

一种可能的解决方案:

首先,计算您的p值。这是一个带有z检验的示例,但请使用适合您数据的任何内容:

scale_color_manual()

<.05, the colors remain as specified below in

,然后将颜色美学映射到等于
set.seed(123) terms <- c("covariate1", "covariate2", "covariate3", "covariate4") outcomes <- c("Outcome1", "Outcome2", "Outcome3") treatments <- c("Treatment A", "Treatment B") results <- expand.grid(term = terms, outcome = outcomes, treatment = treatments) %>% mutate( term = factor(term, levels = terms), estimate = rnorm(n(), 0, 0.2), se = runif(n(), 0.05, 0.2), conf.low = estimate - 1.96 * se, conf.high = estimate + 1.96 * se ) ggplot(results, aes(x = estimate, y = term, color = outcome)) + geom_vline(xintercept = 0, color = "black", linetype = "dashed") + geom_point(size = 2, position = position_dodge(width = 0.2)) + geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0, position = position_dodge(width = 0.2)) + facet_wrap(~ treatment) + scale_color_manual(values = c("Outcome1" = "gold3", "Outcome2" = "green3", "Outcome3" = "salmon")) + theme_minimal()

的新因子向量,除非p> = 0.10:

results <- results %>% mutate( p.value = 2 * (1 - pnorm(abs(estimate / se))) )
为了在传说中保持结果,即使没有意义,我们也需要将
r ggplot2
1个回答
1
投票
添加到

color = factor( if_else(p.value < 0.10, outcome, "n.s."), levels = c(levels(outcome), "n.s.") )

drop = FALSE

scale_color_manual()

show.legend = TRUE

geom_point()

geom_errorbarh()
。我们还需要添加美学

group = outcome

,以便仍然像以前一样工作。
将alpha映射到一个新的因子向量,即小于0.05,而另一个级别则是:
position_dodge()
使用
alpha = cut(p.value, c(0, 0.05, 1))
定义alpha值:
scale_alpha_manual()
将它们全部投入在一起(请注意,我使用了不同的种子):
scale_alpha_manual(
  values = c(1, 0.5),
  guide = "none"
)

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.