Remover a legenda ggplot 2. 2
Estou a tentar manter a legenda de uma camada (suave) e remover a legenda da outra (ponto) com o programa.argumento de lendas, mas a lenda continua. Aqui está o código:
ggplot(a[a$variable=="ratio1",], aes(x=new.cor1, y=value))+
geom_point(aes(x=new.cor1, y=value, color=mntn1...1., show.legend=F), size=0.001)+
geom_point(data=tbl1.cnds1, aes(x=new.cor1.cnds, y=ratio1.cnds), shape=5)+
geom_smooth(data=a, aes(x=new.cor1, y=value, colour=variable, show.legend=T),
size=0.5, span=0.05, show.legend=T)+
labs(title="Manhattan plot", x="position", y="zygosity score", colour = "", fill="")+
theme(axis.text.x = element_text(size=11),
axis.text.y = element_text(size=18),
legend.text=element_text(size=17),
legend.key.size = unit(1, "cm"),
plot.title=element_text(size=25, vjust=3),
plot.margin = unit(c(1,0.9,1,1), "cm"),
axis.text=element_text(size=10),
axis.title = element_text(size=24),
axis.title.y=element_text(margin=margin(r = 13)),
axis.title.x=element_text(margin = margin(t = 10)))+
scale_y_continuous(limits = c(0, 1))+
scale_x_continuous(breaks=breaks, labels=labels)+
geom_text(data=tbl1.cnds1, aes(x=new.cor1.cnds, y=ratio1.cnds, label=cnds.gene),
size=2, hjust=-0.2)+
guides(colour=FALSE)
135
3 answers
De R cookbook , onde a bp é o teu ggplot:
Remover a legenda para uma estética em particular (preenchimento):
bp + guides(fill=FALSE)
Também pode ser feito ao especificar a escala:
bp + scale_fill_discrete(guide=FALSE)
Isto remove todas as lendas:
bp + theme(legend.position="none")
299
Author: user3490026, 2016-02-25 08:48:49
Pode haver outra solução para isto:
O teu código era:
geom_point(aes(..., show.legend = FALSE))
Pode especificar o parâmetro show.legend
Após a chamada aes
:
geom_point(aes(...), show.legend = FALSE)
Então a legenda correspondente deve desaparecer
36
Author: Tjebo, 2018-10-05 09:51:01
Se o seu gráfico usar tanto fill
como color
estética, pode remover a legenda com:
+ guides(fill=FALSE, color=FALSE)
5
Author: duhaime, 2018-08-20 02:48:42