ggplot2中修改图例的位置

 

001、默认绘图

bp <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + 
  geom_boxplot()    ## 绘图
bp                  ## 输出图片

 

 

002、上部

bp + theme(legend.position="top")       ## 放在上部

 

 

003、左侧

bp + theme(legend.position="left")   ## 左侧

 

 

004、下部

bp + theme(legend.position="bottom")    ## 下部

 

005、 也可以根据坐标来设置图例的位置, 左下角为 (0,0), 右上角为(1,1)

bp + theme(legend.position=c(.8, .2))

 

参考:https://www.jb51.net/article/256254.htm

 

posted @ 2023-03-23 18:10  小鲨鱼2018  阅读(683)  评论(0编辑  收藏  举报