【发布时间】:2021-04-07 04:48:57
【问题描述】:
我正在使用此代码:
library(ggplot2)
library(reshape)
mtcars <- melt(mtcars, id="am")
mtcars$am <- as.character(mtcars$am)
p <- ggplot(mtcars, aes(x = variable, y = value)) +
geom_boxplot(aes(color = am), width = 0.4, size = 0.4, position = position_dodge(0.6),
outlier.shape=NA, notch=T) +
scale_color_manual(values = c("red", "blue")) +
guides(fill = guide_legend(reverse=TRUE)) +
scale_fill_discrete(name="No name", labels=c("A", "B")) + #Why does this line not work?
coord_flip()
p
为什么图例名称和变量名称不变?我该如何更改它们?
【问题讨论】:
-
尝试将
name="No name", labels=c("A", "B")放入scale_color_manual()而不是scale_fill_discrete()可能吗? -
哇,是的,这行得通!惊人的!谢谢。
标签: r ggplot2 legend boxplot tidy