ggplot 颜色图例正确,情节错误?

ggplot colors correct on legend, wrong on plot?

图例看起来正确,但绘制的最后两条 geom_line 曲线(e.x 和 ten.x)在图上显示为灰色。

如何修复?

1

Xp <- 1:20/5
X <- -10:10/5
X10 <- -10:5/5

df <- data.frame(
    x = Xp, 
    log2.x. = log2(Xp),
    log.x. = log(Xp),
    log10.x. = log10(Xp)) %>%
  full_join(data.frame(
    x = X,
    two.x = 2 ** X,
    e.x = exp(X))) %>%
  full_join(data.frame(
    x = X10,
    ten.x = 10 ** X10)) %>%
  pivot_longer(cols = -c(x), names_to = "transformation") %>%
  mutate(name = factor(transformation, levels = unique(transformation)))

df %>% ggplot(aes(x=x, y=value, color=transformation)) + 
  geom_line() +
  scale_color_manual(values = c(
    "log2.x." = "red",
    "log.x" = "green",
    "log10.x" = "blue",
    "two.x" = "red",
    "e.x" = "green",
    "ten.x" = "blue"))

。有时会很生气 :D

df%>% ggplot(aes(x=x, y=value, color=transformation)) + 
  geom_line() +
  scale_color_manual(values = c(
    "log2.x." = "red",
    "log.x." = "green",
    "log10.x." = "blue",
    "two.x" = "red",
    "e.x" = "green",
    "ten.x" = "blue"))