plot与legend画图与图例
畫圖與圖例:
legend(x, y = NULL, legend, fill = NULL, col = par("col"),
?????????border = "black", lty, lwd, pch,
?????????angle = 45, density = NULL, bty = "o", bg = par("bg"),
?????????box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),
?????????pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
?????????xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,
?????????adj = c(0, 0.5), text.width = NULL, text.col = par("col"),
?????????text.font = NULL, merge = do.lines && has.pch, trace = FALSE,
?????????plot = TRUE, ncol = 1, horiz = FALSE, title = NULL,
?????????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 | 字符或表達(dá)式向量 |
| fill | 用特定的顏色進(jìn)行填充 |
| col | 圖例中出現(xiàn)的點(diǎn)或線的顏色 |
| border | 當(dāng)fill = 參數(shù)存在的情況下,填充色的邊框 |
| lty, lwd | 圖例中線的類型與寬度 |
| pch | 點(diǎn)的類型 |
| angle | 陰影的角度 |
| density | 陰影線的密度 |
| bty | 圖例框是否畫出,o為畫出,默認(rèn)為n不畫出 |
| bg | bty != "n"時(shí),圖例的背景色 |
| box.lty, box.lwd, box.col | bty = "o"時(shí),圖例框的類型,box.lty決定是否為虛線,box.lwd決定粗線,box.col決定顏色 |
| pt.bg | 點(diǎn)的背景色 |
| cex | 字符大小 |
| pt.cex | 點(diǎn)的大小 |
| pt.lwd | 點(diǎn)的邊緣的線寬 |
| x.intersp | 圖例中文字離圖片的水平距離 |
| y.intersp | 圖例中文字離圖片的垂直距離 |
| adj | 圖例中字體的相對(duì)位置 |
| text.width | 圖例字體所占的寬度 |
| text.col | 圖例字體的顏色 |
| text.font | 圖例字體 |
| merge | logical, if TRUE,合并點(diǎn)與線,但不填充圖例框,默認(rèn)為TRUE |
| trace | logical; if TRUE顯示圖例信息. |
| plot | logical. If FALSE不畫出圖例 |
| ncol | 圖例中分類的列數(shù) |
| horiz | logical; if TRUE,水平放置圖例 |
| title | 給圖例加標(biāo)題 |
| inset | 當(dāng)圖例用關(guān)鍵詞設(shè)置位置后,inset = 分?jǐn)?shù),可以設(shè)置其相對(duì)位置 |
| xpd | xpd=FALSE,即不允許在作圖區(qū)域外作圖,改為TRUE即可,與par()參數(shù)配合使用。 |
| title.col | 標(biāo)題顏色 |
| title.adj | 圖例標(biāo)題的相對(duì)位置,0.5為默認(rèn),在中間。0最左,1為最右。 |
| seg.len | lty 與lwd的線長(zhǎng),長(zhǎng)度單位為字符寬度 |
先畫出每個(gè)樣本的forehead位置的sweat gland 數(shù)量
| 1 | plot(forehead~sample,pch=15,col="DarkTurquoise",ylim=c(0,400),ylab="Number of active sweat glands per cm2",main="Number of active sweat glands per cm2 in forehead, forearm and back")#pch表示散點(diǎn)用什么形狀表示,col表示顏色,ylim表示Y軸范圍,ylab表示Y軸標(biāo)題,main表示圖片標(biāo)題 |
接著畫出每個(gè)樣本forearm位置的sweat gland 數(shù)量
注意,這里不用plot函數(shù)畫forearm和sample之間的關(guān)系,因?yàn)闀?huì)把上面forehead和sample的圖覆蓋住,為了實(shí)現(xiàn)多個(gè)因變量和一個(gè)自變量在同一個(gè)圖片里,我們要用points或者lines函數(shù)畫其他因變量和自變量的值
| 1 | points(sample,forearm,pch=16,col="DeepPink",cex=1)#cex表示散點(diǎn)的大小 |
畫出back位置的sweat gland 數(shù)量
| 1 | points(sample,back,pch=17,col="RosyBrown",cex=1) |
把14個(gè)樣本在forehead,forearm和back不同位置的sweat gland 數(shù)量用線連起來
| 1 2 3 | lines(forehead,col="DarkTurquoise",lty=1)#lty=1表示用實(shí)線連起來 lines(forearm,col="DeepPink",lty=2)#lty=2表示用虛線連起來 lines(back,col="RosyBrown",lty=3)#lty=3表示用點(diǎn)線連起來 |
legend函數(shù),圖例說明:
| 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軸坐標(biāo)為12,400表示y軸坐標(biāo)為400,意思為圖例的左邊和上邊界限,text.col表示圖例文本顏色 |
最后,畫出來的圖片效果如下:
轉(zhuǎn)載于:https://www.cnblogs.com/babyfei/p/10514510.html
總結(jié)
以上是生活随笔為你收集整理的plot与legend画图与图例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (八)hope
- 下一篇: 062_判断用户输入的是 Yes 或 N