R 如何将cuminc功能与ggplot2配合使用
有人知道如何将cominc函数从cmprisk包安装到ggplot2包吗 我收到以下错误消息: 不知道如何为cuminc类型的对象自动拾取比例。 默认为连续 -as.data.frame.default(x[[i]],optional=TRUE,stringsAsFactors=stringsAsFactors)中出现错误:kan-ike-tvinge-klasse »“cuminc”«ind i en data.frameR 如何将cuminc功能与ggplot2配合使用,r,ggplot2,R,Ggplot2,有人知道如何将cominc函数从cmprisk包安装到ggplot2包吗 我收到以下错误消息: 不知道如何为cuminc类型的对象自动拾取比例。 默认为连续 -as.data.frame.default(x[[i]],optional=TRUE,stringsAsFactors=stringsAsFactors)中出现错误:kan-ike-tvinge-klasse »“cuminc”«ind i en data.frame ggplot2不知道如何处理cuminc类的数据 我找到了一个分割
- ggplot2不知道如何处理cuminc类的数据
cs.cuminc <- function(x,cause="1"){
if (!is.null(x$Tests))
x <- x[names(x) != "Tests"]
which.out <- which(unlist(strsplit(names(x), " "))[seq(2,length(names(x))*2,2)]!=cause)
x[which.out] <- NULL
class(x) <- "cuminc"
return(x)
}
cs.cuminc将数据从cuminc结构移动到数据帧,然后使用ggplot geom_step()
ciplot太棒了!谢谢。这似乎只有在我将“1:nc”更改为“1:(nc-1)”时才适用
ciplot <- function(c, title = "Cumulative incidence", xlim = -1, ylim = 1, ...)
{
nc <- length(c)
d <- data.frame()
strata <- names(c)
for (i in 1:nc) {
d <- rbind(d, data.frame(time = c[[i]]$time, est = c[[i]]$est, var = c[[i]]$var, strat = strata[i]))
}
if (xlim == -1) xlim = max(d$time)
ggplot(d, aes(time, est, col = strat)) + geom_step(size = 1) + ylim(0, 1) + xlim(0, xlim) +
ggtitle(title)
}