以下使用 ggplot 不产生图例。我想要一个标识条形图颜色的图例:
df1 <- data.frame(Response = factor(c(1,1,2,2,3,3,4,4)),
treatment = factor(c("Active", "Placebo", "Active",
"Placebo", "Active","Placebo","Active","Placebo"),
levels=c("Active","Placebo")),
percent = c(16.81, 13.53, 17.42, 16.24, 25.33, 19.27,
100-16.81-17.42-25.33,100-13.53-16.24-19.25))
# Bar graph, with side-by-side bars
ggplot(data=df1, aes(x=Response, y=percent, fill=treatment, order=treatment)) +
geom_bar(stat="identity", position=position_dodge()) +
ylab("Percent") + xlab("Outcome") +
scale_x_discrete(breaks=factor(1:4), labels=c("CR","PR","SD","PD"))+
scale_fill_manual(values=c("black","red", name="Response",
breaks=1:2, labels=c("Active","Placebo"))