Legends-ggplot2图例的一些操作


  1. 移除图例
  2. require(ggplot2)
    b = qplot(Sepal.Length,Petal.Length,data=iris,geom="point",colour = Species)
    #有图例
    b
    #去除图例
    b+theme(legend.position="none")#右图

  2.图例位置摆放
    

b = qplot(Species,Sepal.Width,data=iris,geom="boxplot",fill = Species)+scale_fill_brewer(palette = "Pastel2")
b+theme(legend.position="top")

  

 

b+theme(legend.position=c(.92,.9))

  3.移除背景中的边框和背景颜色

  

b+theme(legend.position=c(.92,.9))+theme(legend.key = element_blank())+theme(legend.background = element_blank())

  4.改变图例中key的顺序

b+scale_fill_brewer(palette="Pastel2",limits=c("virginica","versicolor","setosa"))

  5.修改图例名称

b = ggplot(iris,aes(x=Species,y=Sepal.Width,fill = Species))+geom_boxplot()
b+theme(legend.position="top")+labs(fill = "iris-Spec")

  6.移除图例标题
  

b = ggplot(iris,aes(x=Species,y=Sepal.Width,fill = Species))+geom_boxplot()
b+theme(legend.position="top")+guides(fill = guide_legend(title = NULL))

  7.去掉legend的背景色

  1)去掉背景

legend.background = element_blank()

  2)去掉KEY的背景

legend.key = element_blank()

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM