从ggplot2中删除某些图例变量和图例值? [英] remove certain legend variables and legend values from ggplot2?

查看:2143
本文介绍了从ggplot2中删除某些图例变量和图例值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在ggplot2中绘制一个数据框,如下所示:

  ggplot(iris)+ geom_point(aes(x = Sepal .Width,y = Sepal.Length,color = Species,size = Sepal.Length))

相关问题:


  1. 如何从图例中完全删除一个变量?例如,仍然按照 Sepal.Length 的大小分类,但是从图例中删除 Sepal.Length


  2. 如何从图例中删除某个值或一组值?例如,仍按上面的Species颜色点,但在图例中只显示 setosa 的值,并排除 versicolor,virginica



  3. 谢谢。

    解决方案


    1. 正如joran所述,使用 scale_size(guide =none)


    2. scale_color_discrete(breaks =setosa)



    suppose I'm plotting a dataframe in ggplot2 like:

    ggplot(iris) + geom_point(aes(x=Sepal.Width, y=Sepal.Length, color=Species, size=Sepal.Length))
    

    two related questions:

    1. how can I remove a variable altogether from the legend? For example, still size the points by Sepal.Length but remove Sepal.Length from the legend altogether?

    2. how can I remove just a certain value or set of values from the legend? For example, still color the points by Species as above, but in the legend only show the value for setosa and exclude versicolor, virginica?

    thanks.

    解决方案

    1. As commented by joran, use scale_size(guide = "none").

    2. scale_color_discrete(breaks="setosa")

    这篇关于从ggplot2中删除某些图例变量和图例值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆