日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lattice绘图工具

發(fā)布時間:2023/12/16 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lattice绘图工具 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
library(lattice) data1 <- data.frame(x=seq(0,14),y=seq(3,17),z=rep(c("a","b","c"),times=5)) xyplot(y~x,data = data1)


參數(shù)含義
grid.pars網(wǎng)格圖形參數(shù)
fontsize用于文本和符號兩個組件(每個組件都是數(shù)字標量)的列表
clip面板和條帶兩個組件的列表(每個組件都有一個字符串,“開”或“關(guān)”)

show.settings()

lattice包通過顏色區(qū)分不同組別而不是形狀。 xyplot(y~x,groups = z,data = data1) mysettings <- trellis.par.get() mysettings$superpose.symbol$col <-"black" mysettings$superpose.symbol$pch <-1:10 trellis.par.set(mysettings) xyplot(y~x,groups = z,data = data1)



條件變量
graph_function(formula|v,data=,options)
如果條件變量為連續(xù)型,需要轉(zhuǎn)為離散型

xyplot(y~x|z,data = data1,layout=c(3,1))


面板函數(shù)

mypanel <- function(...){panel.abline(a=1,b=1)panel.xyplot(...) } xyplot(y~x|z,data = data1,layout=c(3,1),panel = mypanel)


分組變量
將不同水平的變量疊加到一起

densityplot(~mpg,data = mtcars,lty=1:2,col=1:2,lwd=2,groups = factor(am),main=list("MPG分布",cex=1.5),xlab = "英里/加侖",key=list(column=2,space="bottom",title="類型(0=自動,1=手動)",text=list(levels(factor(mtcars$am))),lines=list(lty=1:2,col=1:2,lwd=2)))


頁面擺放
借助plot函數(shù)的splite和position

graph1 <- xyplot(mpg~wt,data = mtcars,xlab = "重量",ylab = "英里/加侖") displacement <- equal.count(mtcars$disp,number=3,overlap=0) graph2 <- xyplot(mpg~wt|displacement,data= mtcars,layout=c(3,1),xlab = "重量",ylab = "英里/加侖") plot(graph1,split = c(1,1,2,1)) plot(graph2,split = c(2,1,2,1),newpage = FALSE)

plot(graph1,position = c(0,0,0.5,1)) #圖形左下、右上坐標 plot(graph2,position = c(0.6,0.3,1,1),newpage = FALSE)


lattice包繪圖函數(shù)的常用參數(shù)

參數(shù)含義
x要繪制的對象
datax為表達式時,動用一個數(shù)據(jù)框
allow.multiple對于Y1+Y2X/Z,TRUE時重疊繪制Y1X和Y2X,FALSE時繪制Y1+Y2X
outerFALSE繪制疊加,TRUE不在一個面板顯示
box.ratio內(nèi)部矩形長寬比
horizontal水平或者垂直
panel面板函數(shù)
aspect不同面板的寬高比
groups
auto.keys添加分組變量的圖例符號
prepanel
strip
xlab,ylab
scales
subscripts
subset
xlim,ylim
drop.unused.levels
default.scales
options

barchart

trellis.par.get("axis.text") trellis.par.set(list(axis.text = list(cex=1))) barchart(Titanic,layout=c(4,1),auto.key=TRUE)

barchart(Titanic,layout=c(4,1),auto.key=TRUE,scales = list(x="free"))

barchart(Sex~Freq|Class+Age,data = as.data.frame(Titanic),groups=Survived,stack=TRUE,layout=c(8,1),auto.key=TRUE,scales=list(x="free"))

barchart(Sex~Freq|Class+Age,data = as.data.frame(Titanic),groups=Survived,stack=TRUE,layout=c(8,1),auto.key=list(title="Survived",columns=2),scales=list(x="free"))


點圖

dotplot(VADeaths,pch=1:4,col=1:4,main=list("死亡率",cex=1.5),xlab="比率/千人",key=list(column=4,text=list(colnames(VADeaths)),points=list(pch=1:4,col=1:4)))


dotplot(VADeaths,groups = FALSE,layout=c(1,4),aspect=0.5,origin=0,type=c(“p”,“h”))


直方圖
histogram(x,
data,
allow.multiple, outer = TRUE,
auto.key = FALSE,
aspect = “fill”,
panel = lattice.getOption(“panel.histogram”),
prepanel, scales, strip, groups,
xlab, xlim, ylab, ylim,
type = c(“percent”, “count”, “density”),
nint = if (is.factor(x)) nlevels(x)
else round(log2(length(x)) + 1),
endpoints = extend.limits(range(as.numeric(x),
finite = TRUE), prop = 0.04),
breaks,
equal.widths = TRUE,
drop.unused.levels =
lattice.getOption(“drop.unused.levels”),
…,
lattice.options = NULL,
default.scales = list(),
default.prepanel =
lattice.getOption(“prepanel.default.histogram”),
subscripts,
subset)
核密度圖
densityplot(x,
data,
allow.multiple = is.null(groups) || outer,
outer = !is.null(groups),
auto.key = FALSE,
aspect = “fill”,
panel = lattice.getOption(“panel.densityplot”),
prepanel, scales, strip, groups, weights,
xlab, xlim, ylab, ylim,
bw, adjust, kernel, window, width, give.Rkern,
n = 512, from, to, cut, na.rm,
drop.unused.levels =
lattice.getOption(“drop.unused.levels”),
…,
lattice.options = NULL,
default.scales = list(),
default.prepanel =
lattice.getOption(“prepanel.default.densityplot”),
subscripts,
subset)
帶狀圖
panel.stripplot(x, y, jitter.data = FALSE,
factor = 0.5, amount = NULL,
horizontal = TRUE, groups = NULL,
…,
identifier = “stripplot”)
Q-Q圖
根據(jù)理論分布繪制樣本的分位數(shù)-分位數(shù)圖
qqmath(x,
data,
allow.multiple = is.null(groups) || outer,
outer = !is.null(groups),
distribution = qnorm,
f.value = NULL,
auto.key = FALSE,
aspect = “fill”,
panel = lattice.getOption(“panel.qqmath”),
prepanel = NULL,
scales, strip, groups,
xlab, xlim, ylab, ylim,
drop.unused.levels = lattice.getOption(“drop.unused.levels”),
…,
lattice.options = NULL,
default.scales = list(),
default.prepanel = lattice.getOption(“prepanel.default.qqmath”),
subscripts,
subset)
箱型圖
bwplot(x,
data,
allow.multiple = is.null(groups) || outer,
outer = FALSE,
auto.key = FALSE,
aspect = “fill”,
panel = lattice.getOption(“panel.bwplot”),
prepanel = NULL,
scales = list(),
strip = TRUE,
groups = NULL,
xlab,
xlim,
ylab,
ylim,
box.ratio = 1,
horizontal = NULL,
drop.unused.levels = lattice.getOption(“drop.unused.levels”),
…,
lattice.options = NULL,
default.scales,
default.prepanel = lattice.getOption(“prepanel.default.bwplot”),
subscripts = !is.null(groups),
subset = TRUE)
散點圖矩陣

splom(mtcars[c(1,3:7)],groups = mtcars$cyl,pscales = 0 ,pch=1:3,col=1:3,varnames = c("M","D","G","R","W","1/4"),key=list(columns=3,title="數(shù)值",text=list(levels(factor(mtcars$cyl))),points=list(pch=1:3,col=1:3)))


三維水平圖

data(Cars93,package = "MASS") cor_car93 <- cor(Cars93[,!sapply(Cars93,is.factor)],use = "pair") levelplot(cor_car93,scales=list(x=list(rot=90)))


三維等高線圖

contourplot(volcano,cuts=20,label=FALSE)


三維散點圖

parset <- list(axis.line = list(col="transparent"),clip=list(panel="off")) cloud(Sepal.Length~Petal.Length*Petal.Width,data = iris,cex=.8,pch=1:3,col=c("blue","green","red"),groups = Species,screen=list(z=20,x=-70,y=0),par.settings=parset,scales = list(col="black"),key=list(title="種類",column=3,space="bottom",text=list(levels(iris$Species)),points=list(pch=1:3,col=c("blue","green","red"))))


三維曲面圖

wireframe(volcano,shade=TRUE,aspect = c(56/90,0.4),light.source=c(10,0,10))

總結(jié)

以上是生活随笔為你收集整理的lattice绘图工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。