Here's an approach with tidyr::separate_rows
:
library(tidyverse)
separated.data <- data %>%
separate_rows(Change.in.treatment,sep = ", ")
separated.data
# A tibble: 7 x 2
Date Change.in.treatment
<chr> <chr>
1 1/4 Started new medication
2 1/4 changed dose
3 1/5 Started new medication
4 1/6 Stopped medication
5 1/6 Started new medication
6 1/6 New diagnosis
7 1/7 New diagnosis
From here, you can easily make a bar chart with ggplot
:
ggplot(data = separated.data, aes(x = Change.in.treatment)) +
geom_bar(stat = "count")
Sample Data:
data <- structure(list(Date = c("1/4", "1/5", "1/6", "1/7"), Change.in.treatment = c("Started new medication, changed dose",
"Started new medication", "Stopped medication, Started new medication, New diagnosis",
"New diagnosis")), class = "data.frame", row.names = c(NA, -4L
))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…