[R语言绘图]plot函数的使用

来源:互联网 发布:全局最优化算法 编辑:程序博客网 时间:2024/04/29 21:05

R语言中最简单的一个绘图函数就是plot了。如果之前用过matlab,用R画图的时候就很可能会尝试plot这个命令能不能使用。plot(a)一般就能得到我们想要的图。但是,如果想进一步设置其他属性,如标题、x轴名称、y轴名称等,还需要对另外的一些参数做一些了解。下面就给出了一个很简单的例子,看过之后就能掌握plot函数的使用方法了。

attach(mtcars)#获取系统自带的data.frame类型的数据mtcarsclass(mtcars)mtcarsmtcars<-mtcars[order(mtcars$wt),]#为了更清楚展示结果,将数据表按照wt列从小到大排序#简单的画图plot(mtcars$mpg)plot(mtcars$wt,mtcars$mpg)#设置所有可用的参数plot(x = mtcars$wt,     y = mtcars$mpg,     type="o",#线型     main="标题",     sub="子标题",     xlab="x轴",     ylab="y轴",     asp=0.1)#y/x的比例,y轴数值长度与x轴数值长度的比值

另外需要补充的是,type线型参数的其他一些选择。

点"p" for points,线"l" for lines,点线"b" for both,点线图去掉点"c" for the lines part alone of "b",覆盖式的电线"o" for both ‘overplotted’,类似直方图"h" for ‘histogram’ like (or ‘high-density’) vertical lines,楼梯状"s" for stair steps,楼梯状"S" for other steps, see ‘Details’ below,不显示"n" for no plotting.

结果示意图


参考:help(plot)

转载请注明出处:http://blog.csdn.net/zhyoulun/article/details/46410123

1 0
原创粉丝点击