编辑图例 - R.

时间:2018-03-28 19:14:21

标签: r ggplot2 legend

我使用ggplot创建了一个图,用于绘制对药物组合的不同反应。我要做的一件事就是改变传说来自" 0"和" 1"到"部分回应"和/和稳定的疾病。我尝试了以下代码,但我一直收到错误:

scale_fill_manual(labels = c("Partial Response", "Stable Disease"))

" f(...)中的错误:参数"值"缺少,没有默认"

这是我的原始代码:

ggplot(data = mdcf_plot, aes(x=reorder(DMP.ID, -OS), y=OS, fill = factor(Best.Response))) 
+ ylim(0,50) + ylab("Overall Survival (months)") + xlab("Response by DMP ID") 
+ theme_classic() + ggtitle("Overall Survival in Patients Treated with XYZ (n=11)") 
+ theme(plot.title = element_text(hjust = 0.5)) 
+ geom_bar(stat="identity", width = 0.4) + guides(fill = guide_legend(title 
= "Best Response"))

如何调整scale_fill_code以编辑这些标签?

1 个答案:

答案 0 :(得分:1)

请改用scale_fill_discrete。例如

ggplot(mpg, aes(cty, hwy, fill=factor(cyl))) + 
    geom_tile() + 
    scale_fill_discrete(labels=c("four","five","six","eight"))

或者将值添加到scale_fill_manual()

scale_fill_manual(values 0:1, labels = c("Partial Response", "Stable Disease"))

但这真的只适用于您想要自己指定颜色的情况,而您似乎并不想这样做。

相关问题