plot與legend畫圖與圖例

畫圖與圖例:函數

legend(x, y = NULL, legend, fill = NULL, col = par("col"),字體

         border = "black", lty, lwd, pch,spa

         angle = 45, density = NULL, bty = "o", bg = par("bg"),code

         box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),blog

         pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,圖片

         xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,ci

         adj = c(0, 0.5), text.width = NULL, text.col = par("col"),string

         text.font = NULL, merge = do.lines && has.pch, trace = FALSE,it

         plot = TRUE, ncol = 1, horiz = FALSE, title = NULL,io

         inset = 0, xpd, title.col = text.col, title.adj = 0.5,

         seg.len = 2)

x, y

X,y用於定位圖例,也可用單鍵詞"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center"

legend

字符或表達式向量

fill

用特定的顏色進行填充

col

圖例中出現的點或線的顏色

border

當fill = 參數存在的狀況下,填充色的邊框

lty, lwd

圖例中線的類型與寬度

pch

點的類型

angle

陰影的角度

density

陰影線的密度

bty

圖例框是否畫出,o爲畫出,默認爲n不畫出

bg

bty != "n"時,圖例的背景色

box.lty, box.lwd, box.col

bty = "o"時,圖例框的類型,box.lty決定是否爲虛線,box.lwd決定粗線,box.col決定顏色

pt.bg

點的背景色

cex

字符大小

pt.cex

點的大小

pt.lwd

點的邊緣的線寬

x.intersp

圖例中文字離圖片的水平距離

y.intersp

圖例中文字離圖片的垂直距離

adj

圖例中字體的相對位置

text.width

圖例字體所佔的寬度

text.col

圖例字體的顏色

text.font

圖例字體

merge

logical, if TRUE,合併點與線,但不填充圖例框,默認爲TRUE

trace

logical; if TRUE顯示圖例信息.

plot

logical. If FALSE不畫出圖例

ncol

圖例中分類的列數

horiz

logical; if TRUE,水平放置圖例

title

給圖例加標題

inset

當圖例用關鍵詞設置位置後,inset = 分數,能夠設置其相對位置

xpd

xpd=FALSE,即不容許在做圖區域外做圖,改成TRUE便可,與par()參數配合使用。

title.col

標題顏色

title.adj

圖例標題的相對位置,0.5爲默認,在中間。0最左,1爲最右。

seg.len

lty 與lwd的線長,長度單位爲字符寬度

接着畫出每一個樣本forearm位置的sweat gland 數量

注意,這裏不用plot函數畫forearm和sample之間的關係,由於會把上面forehead和sample的圖覆蓋住,爲了實現多個因變量和一個自變量在同一個圖片裏,咱們要用points或者lines函數畫其餘因變量和自變量的值

1
points (sample,forearm,pch=16,col= "DeepPink" ,cex=1) #cex表示散點的大小

畫出back位置的sweat gland 數量

1
points (sample,back,pch=17,col= "RosyBrown" ,cex=1)

把14個樣本在forehead,forearm和back不一樣位置的sweat gland 數量用線連起來

1
2
3
lines (forehead,col= "DarkTurquoise" ,lty=1) #lty=1表示用實線連起來
lines (forearm,col= "DeepPink" ,lty=2) #lty=2表示用虛線連起來
lines (back,col= "RosyBrown" ,lty=3) #lty=3表示用點線連起來

legend函數,圖例說明:

1
legend (12,400, c ( "forehead" , "forearm" , "back" ),col= c ( "DarkTurquoise" , "DeepPink" , "RosyBrown" ),text.col= c ( "DarkTurquoise" , "DeepPink" , "RosyBrown" ),pch= c (15,16,17),lty= c (1,2,3)) #12表示x軸座標爲12,400表示y軸座標爲400,意思爲圖例的左邊和上邊界限,text.col表示圖例文本顏色

最後,畫出來的圖片效果以下:

相關文章
相關標籤/搜索