R Lattice:Stacked/Superposed bwplot with groups
R Lattice: Stacked/Superposed bwplot with groups
我快要生产出我想要的东西了。
vcDeciles <- ceiling(runif(100,1,10))
vcY <- runif(100,0,10)
vcPlotGroups <- sample(c("Pre","Post","Both"),100,1)
vcPlotColors <- 1:length(levels(as.factor(vcPlotGroups)))
print(bwplot(vcY~vcDeciles,ylim=c(min(vcY),max(vcY)),horizontal=F,main="test"
,groups=vcPlotGroups
,col=vcPlotColors
,panel=function(x,y,...) {panel.superpose(x,y,...,panel.groups=function(x,y,col,...) {
panel.bwplot(x,y,col=col,...)
panel.abline(lm(y~x),col.line=col)})}
,key=list(space="top",text=list(levels(as.factor(vcPlotGroups)),lines=list(col=vcPlotColors,lwd=6)))))
问题:
1) 图例中未显示颜色。根据其他有效的图,("Both" = 黑色;"Post" = 红色,"Pre" = 绿色)
2)"Post"组的填充色不能是淡蓝色,应该是黑色。 abline
使用正确的颜色。
对于你的关键问题,我认为你只是遇到了括号匹配问题。那么我认为更改箱线图颜色的最简单方法就是将 fill=
也传递给面板函数。例如
bwplot(vcY~vcDeciles,ylim=c(min(vcY),max(vcY)),
horizontal=F,
main="test",
groups=vcPlotGroups,
col=vcPlotColors,
panel=function(x,y,...) {
panel.superpose(x,y,...,panel.groups=function(x,y,col,fill,...) {
panel.bwplot(x,y,col=col,fill=col, ...)
panel.abline(lm(y~x),col.line=col)}
)
},
key=list(space="top",
text=list(levels(as.factor(vcPlotGroups))),
lines=list(col=vcPlotColors,lwd=6)),
par.settings = list(superpose.polygon=list(color="black"))
)
将return
我快要生产出我想要的东西了。
vcDeciles <- ceiling(runif(100,1,10))
vcY <- runif(100,0,10)
vcPlotGroups <- sample(c("Pre","Post","Both"),100,1)
vcPlotColors <- 1:length(levels(as.factor(vcPlotGroups)))
print(bwplot(vcY~vcDeciles,ylim=c(min(vcY),max(vcY)),horizontal=F,main="test"
,groups=vcPlotGroups
,col=vcPlotColors
,panel=function(x,y,...) {panel.superpose(x,y,...,panel.groups=function(x,y,col,...) {
panel.bwplot(x,y,col=col,...)
panel.abline(lm(y~x),col.line=col)})}
,key=list(space="top",text=list(levels(as.factor(vcPlotGroups)),lines=list(col=vcPlotColors,lwd=6)))))
问题:
1) 图例中未显示颜色。根据其他有效的图,("Both" = 黑色;"Post" = 红色,"Pre" = 绿色)
2)"Post"组的填充色不能是淡蓝色,应该是黑色。 abline
使用正确的颜色。
对于你的关键问题,我认为你只是遇到了括号匹配问题。那么我认为更改箱线图颜色的最简单方法就是将 fill=
也传递给面板函数。例如
bwplot(vcY~vcDeciles,ylim=c(min(vcY),max(vcY)),
horizontal=F,
main="test",
groups=vcPlotGroups,
col=vcPlotColors,
panel=function(x,y,...) {
panel.superpose(x,y,...,panel.groups=function(x,y,col,fill,...) {
panel.bwplot(x,y,col=col,fill=col, ...)
panel.abline(lm(y~x),col.line=col)}
)
},
key=list(space="top",
text=list(levels(as.factor(vcPlotGroups))),
lines=list(col=vcPlotColors,lwd=6)),
par.settings = list(superpose.polygon=list(color="black"))
)
将return