How can you convert a charcter variable to timeseries to use use line charts

How can you convert a character variable to time series to use in line charts?

suppose the x-axis variable named as "visits" has data as (screening day, cycle 1 day 1, cycle 1 day 9, cycle 2 day 1, cycle 2 day 9 ..... Final day)
an you use a numeric variable named as "results" on y-axis (10, 12, 11, 24, 18 ...) , how do you convert the x-axis variable to a numeric or time-series for using it on a line chart?

You can change the character to a factor specifying the levels and that order will be used when plotting. See example below:

library(tidyverse)

dat_examp <- tibble(
   visits=c("screening day", "cycle day 1", "cycle 1 day 9", "cycle 2 day 1", "cycle 2 day 9", "Final day"),
   results= c(10, 12, 11, 24, 18, 11)
) %>%
   mutate(
      visits_f=factor(visits, levels=c("screening day", "cycle day 1", "cycle 1 day 9", "cycle 2 day 1", "cycle 2 day 9", "Final day"))
   )

dat_examp %>%
   ggplot(aes(x=visits_f, y=results, group="one")) +
   geom_point() + geom_line()

Created on 2021-10-15 by the reprex package (v2.0.1)

Thank you so much, @StatSteph!

This topic was automatically closed 21 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.