有没有人知道一种方法来适应从cmprisk包到ggplot2包的cominc函数?
我收到此错误消息:
不知道如何自动选择cuminc类型对象的比例 . 默认为连续 - 在as.data.frame.default(x [[i]],可选= TRUE,stringsAsFactors = stringsAsFactors)中出错:kan ikke tvinge klasse»“cuminc”«ind i en data.frame ggplot2不知道如何处理类cuminc的数据
我找到了一个分割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)
}
这提供了一条带有两条曲线的图 - stil ggplot2无法处理该函数 .
1 回答
将数据从cuminc结构移动到数据帧,然后使用ggplot geom_step():