【发布时间】:2012-09-12 20:41:23
【问题描述】:
@ROLO 的以下代码在回答我之前的问题时生成了 3 个图:
require(mice)
require(reshape2)
require(ggplot2)
dt <- nhanes
impute <- mice(dt, seed = 23109)
# Obtain the imputed data, together with the original data
imp <- complete(impute,"long", include=TRUE)
# Melt into long format
imp <- melt(imp, c(".imp",".id","age"))
# Add a variable for the plot legend
imp$Imputed<-ifelse(imp$".imp"==0,"Observed","Imputed")
# Plot. Be sure to use stat_density instead of geom_density in order
# to prevent what you call "unwanted horizontal and vertical lines"
ggplot(imp, aes(x=value, group=.imp, colour=Imputed)) +
stat_density(geom = "path",position = "identity") +
facet_wrap(~variable, ncol=2, scales="free")
我的问题是,如何修改它以单独绘制每个?
【问题讨论】:
-
这只是一个评论,以便@ROLO 得到通知,谁写了这段代码来回答我之前的问题。
-
只需在每个数据子集上精确绘制三次?
-
@joran 谢谢!效果很好 - 我刚刚在调用 ggplot 之前做了
imp <- imp[imp$variable=='bmi',],其他人也这样做了