让我们从您的第二个问题开始:如果您的数据在一个单一的rds.data.frame
中,您可以轻松地将您的三个站点绘制在同一个图表上。
首先,让我们像你一样创建一个列表
set.seed(1)
site1_df <-as.rds.data.frame(data.frame(id=1:10,recruiter.id=c("seed",5,7,3,8,2,10,9,1,6),network.size.variable=c(5,4,8,9,1,2,6,7,10,3),site1=as.factor(sample(c("blue", "red"), 10, replace = TRUE))))
site2_df <-as.rds.data.frame(data.frame(id=1:10,recruiter.id=c("seed",5,7,3,8,2,10,9,1,6),network.size.variable=c(5,4,8,9,1,2,6,7,10,3),site2=as.factor(sample(c("blue", "red"), 10, replace = TRUE))))
site3_df <-as.rds.data.frame(data.frame(id=1:10,recruiter.id=c("seed",5,7,3,8,2,10,9,1,6),network.size.variable=c(5,4,8,9,1,2,6,7,10,3),site3=as.factor(sample(c("blue", "red"), 10, replace = TRUE))))
sites_list <-list(site1_df,site2_df,site3_df)
然后将列表减少到一个rds.data.frame
:
sites_df <-Reduce(function(...) merge(..., all=T), sites_list)
sites_rds <-as.rds.data.frame(sites_df)
然后,您可以在同一图表中绘制所有站点:
convergence.plot(sites_rds,c("site1","site2","site3"), est.func=RDS.I.estimates)

对于您的第一个问题,您必须convergence.plot2
基于convergence.plot
. 下面的convergence.plot2
函数ylab
为xlab
您的title
. 根据自己的喜好更改它们。确保更改所有出现的情况。
convergence.plot2 <-function (rds.data, outcome.variable, est.func = RDS.II.estimates,
as.factor = FALSE, ...)
{
if (as.factor) {
for (o in outcome.variable) {
rds.data[[o]] <- as.factor(rds.data[[o]])
}
}
f <- function(v) cumulative.estimate(rds.data, v, est.func,
...)
ests <- lapply(outcome.variable, f)
make.plot <- function(i) {
Var1 <- Var2 <- value <- NULL
e <- ests[[i]]
nm <- outcome.variable[i]
if (ncol(e) == 2) {
e1 <- e[, 2, drop = FALSE]
attr(e1, "n") <- attr(e, "n")
e <- e1
nm <- paste0(outcome.variable[i], "=", colnames(e)[1])
rds.data[[outcome.variable[i]]] <- as.factor(rds.data[[outcome.variable[i]]])
}
if (ncol(e) > 1) {
rownames(e) <- attr(e, "n")
dat <- melt(e)
datl <- melt(e[nrow(e), , drop = FALSE])
p <- ggplot(dat) + geom_line(aes(x = Var1, color = as.factor(Var2),
y = value)) + scale_color_hue(nm) + ylab("Y-axis Estimate") +
xlab("X-Axis # of Observations") + scale_y_continuous(limits = c(0,
1)) + theme_bw()
p <- p + geom_hline(data = datl, aes(yintercept = value,
color = as.factor(Var2)), linetype = 2, alpha = 0.5)
p
}
else {
dat <- data.frame(value = e[, 1], Var1 = attr(e,
"n"))
datl <- dat[nrow(dat), , drop = FALSE]
v <- rds.data[[outcome.variable[i]]]
rng <- if (!is.numeric(v))
c(0, 1)
else range(v, na.rm = TRUE)
p <- ggplot(dat) + geom_line(aes(x = Var1, y = value)) +
ylab(paste("Estimated", nm)) + xlab("# of Observations") +
scale_y_continuous(limits = rng) + theme_bw()
p <- p + geom_hline(data = datl, aes(yintercept = value),
linetype = 2, alpha = 0.5)
p
}
return(p + ggtitle(paste("Your title Convergence plot of", nm)))
}
plots <- lapply(1:length(outcome.variable), make.plot)
do.call(.grid.arrange_RDS, plots)
}
然后将这个新功能添加到RDS
环境中很重要。RDS
使用只能在自己的环境中找到的功能。
environment(convergence.plot2) <- asNamespace('RDS')
调用convergence.plot2:
convergence.plot2(sites_rds,c("site1","site2","site3"), est.func=RDS.I.estimates)
