Swimmer_plot error

hello, here is my dataset obtained from datapasta:
data.frame(
stringsAsFactors = FALSE,
patient_ID = c("1","2","3","4","5","6",
"7","8","9","10","11","12","13","14","15","16",
"17","18","19"),
Time = c(1596,1514,356,2085,1921,
318,83,328,815,1854,159,240,821,720,2315,1800,99,
205,177)

I'm trying to obtain a Swimmer's plot for this data. I have entered the following:
H_N_outcomes_first20$Time <- as.numeric(H_N_outcomes_first20$Time)
H_N_outcomes_first20$patient_ID <- as.character(H_N_outcomes_first20$patient_ID)
swimmer_plot(df=H_N_outcomes_first20, id="patient_ID", end= "Time", fill='lightblue', width=0.85)

I get the following error message:

Error in model.frame.default(formula = df[, end] ~ df[, id]) :
invalid type (list) for variable 'df[, end]'

Can someone please help?

Thanks

Hi @saurabh,
This example works with your data - the specification of the data.frame columns did not need any modification.

suppressPackageStartupMessages(library(swimplot))
suppressPackageStartupMessages(library(ggplot2))

H_N_outcomes_first20 <- data.frame(stringsAsFactors = FALSE,
                                   patient_ID = c("1","2","3","4","5","6",
                                                  "7","8","9","10","11","12",
                                                  "13","14","15","16","17","18","19"),
                                   Time = c(1596,1514,356,2085,1921,318,83,328,815,
                                            1854,159,240,821,720,2315,1800,99,205,177))

H_N_outcomes_first20
#>    patient_ID Time
#> 1           1 1596
#> 2           2 1514
#> 3           3  356
#> 4           4 2085
#> 5           5 1921
#> 6           6  318
#> 7           7   83
#> 8           8  328
#> 9           9  815
#> 10         10 1854
#> 11         11  159
#> 12         12  240
#> 13         13  821
#> 14         14  720
#> 15         15 2315
#> 16         16 1800
#> 17         17   99
#> 18         18  205
#> 19         19  177

swimmer_plot(df=H_N_outcomes_first20, 
            id="patient_ID", 
            end= "Time", 
            fill='lightblue', 
            width=0.85)

Created on 2021-06-29 by the reprex package (v2.0.0)

Many thanks

Works well! Finally got my swimmers plot

1 Like

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.