我想叠加一个直方图和一个表示使用r的晶格包的累积分布函数的xyplot。重叠柱状图和xyplot
我试图用自定义的面板函数来完成这个工作,但似乎无法正确完成 - 我正在挂上一个情节是单变量,一个是双变量,我认为。
下面是一个例子与两个地块我要垂直堆叠:
set.seed(1)
x <- rnorm(100, 0, 1)
discrete.cdf <- function(x, decreasing=FALSE){
x <- x[order(x,decreasing=FALSE)]
result <- data.frame(rank=1:length(x),x=x)
result$cdf <- result$rank/nrow(result)
return(result)
}
my.df <- discrete.cdf(x)
chart.hist <- histogram(~x, data=my.df, xlab="")
chart.cdf <- xyplot(100*cdf~x, data=my.df, type="s",
ylab="Cumulative Percent of Total")
graphics.off()
trellis.device(width = 6, height = 8)
print(chart.hist, split = c(1,1,1,2), more = TRUE)
print(chart.cdf, split = c(1,2,1,2))
我想这些在同一帧叠加,而不是叠加。
下面的代码不起作用,也不做任何我已经尝试它的简单变化:
xyplot(cdf~x,data=cdf,
panel=function(...){
panel.xyplot(...)
panel.histogram(~x)
})
+1 - 我认为这是一个很好的答案。有时候一个简单的解决方案就是需要的。 – thelatemail