2016-02-25 18 views
78

私は1つのレイヤの凡例(スムーズ)を保持し、show.legend引数で他の(凡例)の凡例を削除しようとしていますが、凡例は残っています。 r cookbookから凡例を削除するggplot 2.2

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) 
+3

最小限の再現性の例を消えるはずです。コードの長い行では、(現時点での問題に対して)多くの不必要なコードが存在するように見えるだけでなく、現在書かれているように完全に再現できないように見えます。 – mnel

答えて

191

、BPはあなたのggplotである:ここでは、コードで特定の美的ため

削除伝説(記入):指定する場合にも行うことができます

bp + guides(fill=FALSE) 

規模:これは、すべての伝説を削除

bp + scale_fill_discrete(guide=FALSE) 

bp + theme(legend.position="none") 
+5

@Alexによるコメントへの返信として: 'theme_bw()'は 'theme()'を使って行われた定義に干渉することに注意してください。 'theme_bw()'を使うときは、他のテーマオプションを変更する前に必ずそれをプロットに追加してください。 – fber

10

はこの質問につまずいたが、私はこれまで、別の解決策があるかもしれないと思う: あなたのコードだった:

geom_point(aes(x=new.cor1, y=value, color=mntn1...1., show.legend=F) 

私はあなたが呼ぶ美学の外show.legendを移動するためにあると思います。

geom_point(aes(x=new.cor1, y=value, color=mntn1...1.), show.legend=F) 

その後、特派員の伝説は、はるかに簡単になり

関連する問題