時間:2020.10.15
ggplot2畫圖時進(jìn)行圖例位置的調(diào)整。
參考網(wǎng)址:https://www.omicsclass.com/article/428, https://blog.csdn.net/zx403413599/article/details/48581713
ggplot2作圖:添加和管理標(biāo)題:https://zhuanlan.zhihu.com/p/93224999
在此博客上已經(jīng)講的非常詳細(xì),直接引用。
ggplot2繪圖過程種,控制圖例在圖中的位置利用theme(legend.position)參數(shù) 該參數(shù)對應(yīng)的設(shè)置如下: legend.positionthe position of legends ("none", "left", "right", "bottom", "top", or...
其他類型表示控制具體位置,包括 "left" 左, "right" 右, "bottom" 下, "top" 上,以繪圖過程 https://www.omicsclass.com/article/92 為基礎(chǔ),修改theme(legend.position)
p_bottom=p+theme(legend.position = "bottom")
print(p_bottom)

image.png
但是需要主要,legend.position也可以用兩個元素構(gòu)成的數(shù)值向量來控制,主要是設(shè)置圖例在圖片中間所在具體位置,而不是圖片的外圍。數(shù)值大小一般在0-1之間,超出數(shù)值往往導(dǎo)致圖例隱藏。
c(0.9,0.7)
p_v=p+theme(legend.position = c(0.9,0.7))
print(p_v)

image.png
c(0.9,1.1) 僅出現(xiàn)小半圖例
p_v=p+theme(legend.position = c(0.9,1.1))
print(p_v)

image.png
c(0.9,1.2) 圖例完全超出繪圖板,可以理解隱藏
p_v=p+theme(legend.position = c(0.9,1.2))
print(p_v)

image.png
添加一個 不要圖例操作
# 不要圖例
theme(legend.position='none')