图例与scale_fill_manual颜色不对应(ggplot2)

时间:2016-12-29 20:29:44

标签: r ggplot2 legend

我试图用两组(分别是形状和颜色)制作一个情节,但是" Cap W"与scale_fill_manual颜色不对应。

enter image description here

install.packages("ggplot2")
library(ggplot2)
df <- data.frame(x = 1:5,
                 y = 4:8,
                 z = c("z1", "z1", "z2", "z2", "z3"),
                 w = c("w2", "w3", "w4", "w1", "w1"))

ggplot(df, aes(x, y, shape = z, fill = w)) +
    geom_point(size = 6) +
    scale_shape_manual(name = "Cap Z", values = c(21, 22, 24)) +
    scale_fill_manual(name = "Cap W", values = c("black", "grey30", "grey60", "white")) +
    theme_bw()

有关如何修复的想法吗?

0 个答案:

没有答案