Skip to content

'names' attribute must be the same length as the vector #691

@komalsrathi

Description

@komalsrathi

Hi,

I am trying to run ggsurvplot, and this one's a little tricky for me to debug. I am attaching my Rdata here: ggsurvplot_debug.RData

# load RData object from google drive (attached above)
load('ggsurvplot_debug.RData')

# objects in RData file
> ls()
[1] "fit"       "p"         "surv_data"
  1. I only get the error when I set risk.table = TRUE AND set the palette argument to a custom vector of colors (as shown below):
# use ggsurvplot to generate survival plot (basic arguments)
ggsurvplot(
  fit,
  palette = c("#ff4040",
              "#bf9000",
              "#00BFC4",
              "#9fc5e8",
              "#4363d8",
              "#0000ff",
              "#ffe135",
              "#bf9000",
              "#ffa500",
              "#F8766D",
              "#000000",
              "#dcbeff",
              "#C77CFF",
              "#911eb4",
              "#FF4DC5",
              "#7CAE00"),
  data = surv_data,
  risk.table = T
)

# this is resulting in the following errors
Error in names(.cols) <- grp.levels : 
  'names' attribute [16] must be the same length as the vector [15]
  1. When I set risk.table = FALSE along with custom palette, it works:
# works without an error
ggsurvplot(
  fit,
  palette = c("#ff4040",
              "#bf9000",
              "#00BFC4",
              "#9fc5e8",
              "#4363d8",
              "#0000ff",
              "#ffe135",
              "#bf9000",
              "#ffa500",
              "#F8766D",
              "#000000",
              "#dcbeff",
              "#C77CFF",
              "#911eb4",
              "#FF4DC5",
              "#7CAE00"),
  data = surv_data,
  risk.table = F
)
  1. When I set risk.table = TRUE along and don't assign a custom palette, it works:
# works without an error
ggsurvplot(
  fit,
  data = surv_data,
  risk.table = T
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions