【发布时间】:2017-03-18 07:41:12
【问题描述】:
我想独立使用色标,即用于连续和分类标度。
我有一个特定的应用程序,我有一个像这里这样的简单情节
mtcars %>%
mutate(cylcol = factor(if_else(cyl == 6, "six", "not six"))) %>%
ggplot(aes(x = mpg, y = wt)) +
geom_point(aes(color = drat)) +
facet_wrap(~ cyl)
但我也想要highlight border, like in the answer of Seth_P, of a specific condition(我不想使用填充背景!)。例如
mtcars %>%
mutate(cylcol = factor(if_else(cyl == 6, "six", "not six"))) %>%
ggplot(aes(x = mpg, y = wt)) +
geom_point() +
geom_rect(xmin = -Inf, xmax = Inf, show.legend = FALSE,
ymin = -Inf, ymax = Inf, aes(col = cylcol), fill = "#00000000") +
facet_wrap(~ cyl)
现在我想“结合”这两者,例如:
mtcars %>%
mutate(cylcol = factor(if_else(cyl == 6, "six", "not six"))) %>%
ggplot(aes(x = mpg, y = wt)) +
geom_point(aes(color = drat)) +
geom_rect(xmin = -Inf, xmax = Inf, show.legend = FALSE,
ymin = -Inf, ymax = Inf, aes(col = cylcol), fill = "#00000000") +
facet_wrap(~ cyl)
这会产生错误Error: Discrete value supplied to continuous scale。一方面这是有道理的,但另一方面,由于两者都使用独立变量,我想使用“不同的色标”。我可以使用覆盖,例如here, where facet colors are plotted over the plot,但我非常感谢一个更简单的解决方案。我知道specifying fill and color separately - 但这不是目标。我真的很想在不同的尺度上使用颜色。有什么建议么 ?
【问题讨论】: