我一直在尝试向我的 ggplot 添加图例,但惨败。我确实遇到了与手动添加图例相关的其他问题,例如1,2但无法将答案应用到我的 ggplot 上。我尝试了该功能scale_colour_manual
但传说并没有出现。
任何帮助将非常感激。
p <- ggplot() +
# corine plot
geom_point(data=t, aes(x=FPR, y=TPR),colour="black", size =3,pch=1) +
geom_line(data=t, aes(x=FPR, y=TPR),
colour="lightblue", size=1) +
#globecover plot
geom_point(data=tgl, aes(x=FPR, y=TPR),colour="black",size=3,pch=1) +
geom_line(data=tgl, aes(x=FPR, y=TPR),
colour="red", size=1)+
#grump plot
geom_point(data=tgr, aes(x=FPR, y=TPR),colour="black",size=3, pch=1) +
geom_line(data=tgr, aes(x=FPR, y=TPR),
colour="pink", size=1)
p <- p+geom_abline(intercept=0, slope=1)
p<- p+ labs(list(title = "FPR vs TPR", x = "False Positive Rate", y = "True Positive Rate"))
p <-p+theme_bw() +
theme(axis.title.x = element_text(size = 15, vjust=-.2)) +
theme(axis.title.y = element_text(size = 15, vjust=0.3))
p+ scale_colour_manual(name="legend", value =c("corine"= "lightblue", "globcover"="red", "grump"="pink"))
是的,我的数据t
,tgr
,tgl
看起来像这样:
ID Countries FPR TPR
1 Bristol 0.08716076 0.6894999
2 Brussel 0.18621056 0.8065292
3 Budapest 0.07085285 0.8234692
4 Edinburgh 0.05507682 0.6944172
5 Gozo 0.11037915 0.6360882
等等。