ggsurvplot() error

Hi, apologies for my noobishness in advance. I am attempting to plot a survival curve of time to patient death/retransplant using the ggsurvplot function, with two groups defined by their liver transplant having had an arterial construction or not.

Actual behavior

No curve produce. Error given:

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 236, 0, 472

My R studio and relevant packages appear to be working as I am able to reproduce the standard lung cancer examples, but have clearly done something wrong with my dataset.

Steps to reproduce the problem

library(survival)
library(survminer)
library(dplyr)
library(readr)

github_survival_curve <- read_csv("dataraw/github _survival_curve.csv",
col_types = cols( Any arterial reconstruction (0-No, 1-yes) = col_factor(levels = c("0",
"1")), Event_death = col_factor(levels = c("0",
"1")), Graft_survival = col_integer(),
Survival_to_retransplantation = col_integer()))
View(github_survival_curve)

surv_object <- Surv(time = github_survival_curve$Graft_survival, event = github_survival_curve$Event_death)
surv_object

fit1 <- survfit(surv_object ~ github_survival_curve$ Any arterial reconstruction (0-No, 1-yes) , data = github_survival_curve)
summary(fit1)

ggsurvplot(fit1, data = github_survival_curve, pval = TRUE)

All steps appear to be functioning well apart from the final step which returns:

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 236, 0, 472

Any help or advice would be greatly appreciated, have searched similar issues, but I seem to have stalled at a much earlier junction than most of those.

A data frame in R is definitionally:

A data frame is a list of variables of the same number of rows

So, you're currently erroring out because the data frame object does not have rows of equal length.

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

1 Like

Hi Mara!

Thanks for replying, and for directing me towards those resources, I will definitely use them if I need to post on here again. I couldn't quite work out how to upload my toy data onto my post, so I suspected I might not be able to get a response on here, but luckily I got some help from someone on github.

Essentially, my problem was that I was reading in some of my variables as factors --> which ggsurvplot doesn't like.

github_survival_curve <- read_csv("dataraw/github _survival_curve.csv",
col_types = cols(Any arterial reconstruction (0-No, 1-yes) = col_factor(levels = c("0",
"1")), Event_death = col_factor(levels = c("0",
"1")), Graft_survival = col_integer(),
Survival_to_retransplantation = col_integer()))
View(github_survival_curve)

Redoing this and leaving the variables as default (double) fixed the problem.

Thanks again
jtoa2

Nice. Glad you got it sorted. I'm going to mark as solved!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.