【发布时间】:2020-11-25 22:58:04
【问题描述】:
我正在尝试为同样被刻面的情节的不同象限着色。我注意到geom_rect 参数中的颜色在各个方面看起来不同。我希望这是一个例子:
# Load tidyverse
library(tidyverse)
# Make some fake data
set.seed(5)
dat <- tibble(
y = rnorm(10, 0, 1),
ub = y + .2,
lb = y - .2,
x = sample(1:7, size=10, replace=TRUE),
z = sample(c("one", "two", "three"), size=10, replace=TRUE),
)
# Plot
dat %>%
ggplot(aes(x = x, y = y)) +
geom_rect(data=NULL, aes(xmin=4, xmax=Inf, ymin=0, ymax=-Inf), fill="yellow", color = "white", alpha = .05) +
geom_rect(data=NULL, aes(xmin=-Inf, xmax=4, ymin=Inf, ymax=0), fill="yellow", color = "white", alpha = .05) +
geom_rect(data=NULL, aes(xmin=-Inf, xmax=4, ymin=-Inf, ymax=0), fill="red", color = "white", alpha = .05) +
geom_rect(data=NULL, aes(xmin=4, xmax=Inf, ymin=0, ymax=Inf), fill="springgreen", color = "white", alpha = .05) +
geom_point(position= position_dodge2(width = .6)) +
geom_errorbar(aes(ymin = lb, ymax = ub, width = .6), position= position_dodge2(width = .6, preserve = "single")) +
facet_grid(~ z) +
theme_classic()
谁能向我解释为什么geom_rect 框在某些方面比其他方面更亮?我该如何解决这个问题?
【问题讨论】: