分享

ggplot2图例位置legend.position调整

 脑系科数据科学 2020-03-22

ggplot2绘图过程种,控制图例在图中的位置利用theme(legend.position)参数 该参数对应的设置如下: legend.positionthe position of legends ("none", "left", "right", "bottom", "top", or...

ggplot2绘图过程种,控制图例在图中的位置利用theme(legend.position)参数

该参数对应的设置如下:

legend.position

the position of legends ("none", "left", "right", "bottom", "top", or two-element numeric vector)

其中none 表示隐藏图例,可参考 https://www./article/383

其他类型表示控制具体位置,包括 "left" , "right" ,  "bottom" 下, "top" 上,以绘图过程 https://www./article/92 为基础,修改theme(legend.position) 

p_bottom=p+theme(legend.position = "bottom")
print(p_bottom)

attachments-2018-09-W1zVNsIL5b9a380db6016.jpg

但是需要主要,legend.position也可以用两个元素构成的数值向量来控制,主要是设置图例在图片中间所在具体位置,而不是图片的外围。数值大小一般在0-1之间,超出数值往往导致图例隐藏。

c(0.9,0.7)

p_v=p+theme(legend.position = c(0.9,0.7))
print(p_v)

attachments-2018-09-ICPEGH5C5b9a3959a10ba.jpgc(0.9,1.1)  仅出现小半图例

p_v=p+theme(legend.position = c(0.9,1.1))
print(p_v)

attachments-2018-09-yaaoQ4bP5b9a3a6f50f1e.jpg
c(0.9,1.2)  图例完全超出绘图板,可以理解隐藏

p_v=p+theme(legend.position = c(0.9,1.2))
print(p_v)

attachments-2018-09-K6FyanUd5b9a3a9157e5d.jpg

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多