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()

 

 

 

转载于:https://www.cnblogs.com/yangk/p/4761994.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值