欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

聊聊R语言中Legend 函数的参数用法

程序员文章站 2022-06-28 14:30:40
如下所示:legend(x, y = null, legend, fill = null, col = par("col"),border = "black", lty, lwd, pch,angle...

如下所示:

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

图例中出现的点或线的颜色

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的线长,长度单位为字符宽度

补充:r语言_legend()函数用法

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 | 参数

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的线长,长度单位为字符宽度

example | 例子

> legend("topleft", inset=.05, title="drug type", c("a","b"),
+    lty=c(1, 2), pch=c(15, 17), col=c("red", "blue"))

聊聊R语言中Legend 函数的参数用法

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。