lattice 包高级绘图函数
来源:互联网 发布:成都软件专修学院 编辑:程序博客网 时间:2024/05/21 06:22
1.条形图
barchart()
> barchart(Titanic,layout=c(4,1),auto.key=TRUE,scales=list(x="free")#scales=free 表示各组的x轴的刻度存在不同。如果想要y轴不同时,则要设置成y="free"。
还可以写成如下形式:
barchart(Class~Freq|Sex+Age,data=as.data.frame(Titanic),
groups=Survived,stack=TRUE,layout=c(4,1),
auto.key=TRUE,scales=list(x="free"))# stack=TRUE 表示叠加显示,stack=FALE 表示对比显示即分成两条。
auto.key 表示显示图例。
也可以命名成为函数,然后调用时更改。
> mygraph<-barchart(Freq~Class|Sex+Age,data=as.data.frame(Titanic),
+ groups=Survived,stack=TRUE,layout=c(4,1),
+ auto.key=TRUE,scales=list(x="free"))#这时画出来的是柱状图。
然后对函数进行修改。
update(mygraph,
panel=function(...){
panel.grid(h=0,v=1)
panel.barchart(...,border="transparent")
})# 此处的“...”表示默认,可以在原来的基础上增加一些线条等操作。
2.点图 dotplot
library("lattice")
> head(VADeaths)
Rural Male Rural Female Urban Male Urban Female
50-54 11.7 8.7 15.4 8.4
55-59 18.1 11.7 24.3 13.6
60-64 26.9 20.3 37.0 19.3
65-69 41.0 30.9 54.6 35.1
70-74 66.0 54.3 71.1 50.0
dotplot(VADeaths,pch=1:4,col=1:4,
main=list("Death Rates in Virginia"),
xlab="Rate(per 1000)",
auto.key=TRUE)
如图所示:上面的图例中,自动的图例auto.key 是不准确的,都是以圆点的形式表示。图中的三角等符号并未进行注释,因此要选择其他的注释符号。
dotplot(VADeaths,pch=1:4,col=1:4,
main=list("Death Rates in Virginia"),
xlab="Rate(per 1000)",
key=list(colunm=4,text=list(colnames(VADeaths)),points=list(pch=1:4,col=1:4)))
# 用list()来分别定义图例:多少列,表示什么内容,用什么符号。
但是上图仍然不是太清楚,我们能不能分面板进行呢?
dotplot(VADeaths,groups=FALSE,pch=1:4,col=1:4,
main=list("Death Rates in Virginia"),
xlab="Rate(per 1000)",
key=list(colunm=4,text=list(colnames(VADeaths)),points=list(pch=1:4,col=1:4)))
# 添加groups=FALSE 来实现。
发现图例中的显示并不正确,优化一下。
dotplot(VADeaths,groups=FALSE,layout=c(1,4),
aspect=0.3,origin=0,type=c("p","h"),
main=list("Death Rates in Virginia"),
xlab="Rate(per 1000)")
# aspect 表示图的长宽比(x/y),origin=0 表示下面的坐标轴从0开始,type=("p")只有点,若type=c("p","h")则有点和线。
注意优化时的写法。
- lattice 包高级绘图函数
- R绘图lattice包
- lattice函数包作图函详解
- lattice 包的用法
- 如何在lattice包绘图时在strip中使用表达式,例如$x^2$之类的文字
- lattice 包中的直方图绘制
- R语言lattice包介绍
- R lattice包中的panel函数参数传输的一个问题
- R极简教程-11:高级绘图函数
- js高级函数之闭包
- JavaScript 4.3 函数高级-闭包
- Android 高级绘图
- Android 高级绘图
- 高级画布绘图
- android 高级画布绘图
- Android 高级绘图
- Android 高级绘图
- Android 高级绘图
- RHEL7--UNIT14-linux设备访问
- android 自定义控件
- oracle中rownum、rowid、row_number()、rank()、dense_rank()的用法
- mysql查看表计划
- linux 用vi命令的使用以及vi编辑后的后续保存退出等相关命令的使用
- lattice 包高级绘图函数
- 在Linux系统中,在防火墙中添加端口
- echarts各个配置项详细说明总结
- Android for MSM Project
- 作业2--实训
- 1038. Recover the Smallest Number (30)
- Android RecyclerView详解及实现瀑布流式布局
- Google调试总结
- perl中十进制与十六进制互换函数