2013-08-20 17 views
60

當我如何可以去掉字母「A」從這個代碼生成的傳奇?如果我刪除geom_text,那麼'a'字母不會顯示在圖例中。不過,我想保留geom_text刪除「一」從Legend採用了美學和geom_text

ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) + 
    geom_point() + 
    geom_text(aes(label = Species)) 

回答

74

geom_text設置show.legend = FALSE

ggplot(data = iris, 
     aes(x = Sepal.Length, y = Sepal.Width, colour = Species, shape = Species, label = Species)) + 
    geom_point() + 
    geom_text(show.legend = FALSE) 

的參數show_guide改名爲show.legendggplot2 2.0.0see release news)。


ggplot2 2.0.0

隨着show_guide = FALSE是這樣的...

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width , colour = Species , shape = Species, label = Species) , size=20) + 
geom_point()+ 
geom_text(show_guide = F) 

enter image description here

9

我有一個similar problem。西蒙的解決方案爲我工作,但需要略微扭曲。我沒有意識到,我需要「show_guide = F」給geom_text的參數,而不是用它取代現有的參數 - 這是西蒙的解決方案所顯示的。對於像我這樣的ggplot2 noob,這並不明顯。一個適當的例子是使用了OP的代碼和剛添加這樣缺少的參數:

.. 
geom_text(aes(label=Species), show_guide = F) + 
.. 
6

就像尼克說

下面的代碼仍然會產生錯誤:

geom_text(aes(x=1,y=2,label="",show_guide=F)) 

enter image description here

而:

geom_text(aes(x=1,y=2,label=""),show_guide=F) 

的AES參數之外消除了一個在傳奇

enter image description here