聊聊R語言中Legend 函數(shù)的參數(shù)用法
如下所示:
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 |
字符或表達式向量 |
|
fill |
用特定的顏色進行填充 |
|
col |
圖例中出現(xiàn)的點或線的顏色 |
|
border |
當fill = 參數(shù)存在的情況下,填充色的邊框 |
|
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 |
圖例中分類的列數(shù) |
|
horiz |
logical; if TRUE,水平放置圖例 |
|
title |
給圖例加標題 |
|
inset |
當圖例用關鍵詞設置位置后,inset = 分數(shù),可以設置其相對位置 |
|
xpd |
xpd=FALSE,即不允許在作圖區(qū)域外作圖,改為TRUE即可,與par()參數(shù)配合使用。 |
|
title.col |
標題顏色 |
|
title.adj |
圖例標題的相對位置,0.5為默認,在中間。0最左,1為最右。 |
|
seg.len |
lty 與lwd的線長,長度單位為字符寬度 |
補充:R語言_legend()函數(shù)用法
Add Legends to Plots | 圖例
Usage
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)
Arguments | 參數(shù)
x, y:用于定位圖例,也可用單鍵詞"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center"
legend:字符或表達式向量
fill:用特定的顏色進行填充
col:圖例中出現(xiàn)的點或線的顏色
border:當fill = 參數(shù)存在的情況下,填充色的邊框
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:圖例中分類的列數(shù)
horiz:logical; if TRUE,水平放置圖例
title:給圖例加標題
inset:當圖例用關鍵詞設置位置后,inset = 分數(shù),可以設置其相對位置
xpd:xpd=FALSE,即不允許在作圖區(qū)域外作圖,改為TRUE即可,與par()參數(shù)配合使用。
title.col:標題顏色
title.adj:圖例標題的相對位置,0.5為默認,在中間。0最左,1為最右。
seg.len:lty 與lwd的線長,長度單位為字符寬度
Example | 例子
> legend("topleft", inset=.05, title="Drug Type", c("A","B"),
+ lty=c(1, 2), pch=c(15, 17), col=c("red", "blue"))

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
相關文章
R語言學習筆記缺失數(shù)據(jù)的Bootstrap與Jackknife方法
這篇文章主要為大家介紹了R語言學習筆記關于缺失數(shù)據(jù)的Bootstrap與Jackknife的方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2021-11-11
R語言數(shù)據(jù)可視化分析天貓雙十一銷售額增長率
這篇文章主要為大家介紹了R語言數(shù)據(jù)可視化來分析天貓雙十一銷售額增長率,來一探多年來歷年雙十一銷售額數(shù)據(jù)是否有造假,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11

