R绘图基础(5)坐标轴,图例,标记与标题 您所在的位置:网站首页 坐标轴怎么显示单位名称 R绘图基础(5)坐标轴,图例,标记与标题

R绘图基础(5)坐标轴,图例,标记与标题

2024-06-02 16:41| 来源: 网络整理| 查看: 265

相关参数来控制,它们有

参数描述main主标题sub副标题xlabx轴标记ylaby轴标记xlimx轴上下限(范围)ylimy轴上下限mgp坐标轴标记,坐标字符,坐标刻度线距离坐标轴的行数,默认值为c(3,1,0)

增加一个新的坐标轴使用axis()函数。

参数描述side坐标轴所在的位置,1:下,2:左,3:上,4:右at坐标轴具体位置,通常由自动给出。labels坐标字符串pos坐标轴线所在的行,默认值为重绘所在位置上的原坐标lty线型col颜色las坐标标记与坐标轴方位关系,=0为平等,=2为垂直lwd.ticks坐标刻度线宽度col.ticks坐标刻度线颜色(…)其它par()中可用的参数> # A Silly Axis Example > > # specify the data > x par(mar=c(5, 4, 4, 8) + 0.1) > > # plot x vs. y > plot(x, y,type="b", pch=21, col="red", + yaxt="n", lty=3, xlab="", ylab="") > > # add x vs. 1/x > lines(x, z, type="b", pch=22, col="blue", lty=2) > > # draw an axis on the left > axis(2, at=x,labels=x, col.axis="red", las=2) > > # draw an axis on the right, with smaller text and ticks > axis(4, at=z,labels=round(z,digits=2), + col.axis="blue", las=2, cex.axis=0.7, tck=-.01) > > # add a title for the right axis > mtext("y=1/x", side=4, line=3, cex.lab=1,las=2, col="blue") > > # add a main title and bottom and left axis labels > title("An Example of Creative Axes", xlab="X values", + ylab="Y=X")

R绘图基础(5)坐标轴,图例,标记与标题-图片1

坐标轴

图例使用legend()函数控制

参数描述x,y图例所在位置,可以使用"bottom", "bottomleft", "left", "topleft" ,"top", "topright" ,"right" ,"bottomleft", "center"来指定。inset设置在主绘图边距title图例的标题legend图例的内容…其它par()可用的参数> attach(mtcars) > boxplot(mpg~cyl, main="Milage by Car Weight", + yaxt="n", xlab="Milage", horizontal=TRUE, + col=terrain.colors(3)) > legend("topright", inset=.05, title="Number of Cylinders", + c("4","6","8"), fill=terrain.colors(3), horiz=TRUE)

R绘图基础(5)坐标轴,图例,标记与标题-图片2

图例

文本框使用text或者mtext函数。text可以在主绘图区内加文本框,mtext在边距或者外边距上加文本框。

text(location, “text to place”, pos, …)

mtext(“text to place”, side, line=n, …)

参数描述location图例所在位置pos所在的相对位置,1:下面,2:左边,3:上面,4:右边side所在边距的位置,1:下,2:左,3:上,4:右…其它par()可用的参数> attach(mtcars) > plot(wt, mpg, main="Milage vs. Car Weight", + xlab="Weight", ylab="Mileage", pch=18, col="blue") > text(wt, mpg, row.names(mtcars), cex=0.6, pos=4, col="red")

R绘图基础(5)坐标轴,图例,标记与标题-图片3

文本框



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有