以下四个调用返回的内容似乎完全相同。如何控制面板密度图?谢谢。
library(lattice)
df <- data.frame( y = runif(100) , p = rep(c('a','b'),50) )
histogram(~ y | p , data = df ,
type = "density",
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, ...)
})
histogram(~ y | p , data = df ,
type = "density",
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, bw=100,kernel="gaussian",...)
})
histogram(~ y | p , data = df ,
type = "density",
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, dargs=list(bw=100,kernel="gaussian"),...)
})
histogram(~ y | p , data = df ,
type = "density", bw=100,kernel="gaussian" ,
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, ...)
})
答案 0 :(得分:3)
正如上面的评论所述,您对histogram()
的第三次电话非常接近。您只需要写darg
而不是dargs
。
以下示例显示darg
确实如?panel.densityplot
中所述,可以控制平滑参数:
library(gridExtra) ## For grid.arrange()
library(lattice)
df <- data.frame(y = runif(100) , p = rep(c('a','b'),50))
p1 <- histogram(~ y | p , data = df ,
type = "density",
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, darg=list(bw = 1, kernel="gaussian"),...)
})
p2 <- histogram(~ y | p , data = df ,
type = "density",
panel=function(x, ...) {
panel.histogram(x, ...)
panel.densityplot(x, darg=list(bw = 0.2, kernel="gaussian"),...)
})
grid.arrange(p1,p2)