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