R 无法更改ggplot boxplot图例名称

R 无法更改ggplot boxplot图例名称,r,ggplot2,legend,boxplot,tidy,R,Ggplot2,Legend,Boxplot,Tidy,我正在使用以下代码: 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,

我正在使用以下代码:

 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
库(ggplot2)
图书馆(重塑)

mtcars这能解决您的问题吗

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"),
                     name="No name", labels=c("A", "B")) + 
  guides(fill = guide_legend(reverse=TRUE)) + 
  coord_flip()
p
库(ggplot2)
图书馆(重塑)

mtcars这能解决您的问题吗

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"),
                     name="No name", labels=c("A", "B")) + 
  guides(fill = guide_legend(reverse=TRUE)) + 
  coord_flip()
p
库(ggplot2)
图书馆(重塑)

mtcars试着用
name=“No name”,labels=c(“A”,“B”)
来代替
scale\u fill\u discrete()
也许?哇,是的,这很有效!令人惊叹的!谢谢。试着用
name=“No name”,labels=c(“A”,“B”)
代替
scale\u-fill\u-discrete()
,用
scale\u-color\u-manual()!令人惊叹的!谢谢,是的!完美的非常感谢。:)对完美的非常感谢。:)