Chapter 42 Ten Most Common Symptoms
We examine the Top Most Common Symptoms associated with the Adverse Events and plot them in the bar plot.
BarPlotSymptoms = function(AdverseFoodEvents)
{
Symptoms = str_split(AdverseFoodEvents$Symptoms,',')
AllSymptoms <- data.frame(matrix(unlist(Symptoms),byrow=T),stringsAsFactors=FALSE)
Symptoms = str_split(AdverseFoodEvents$Symptoms,',')
AllSymptoms <- data.frame(matrix(unlist(Symptoms),byrow=T),stringsAsFactors=FALSE)
colnames(AllSymptoms) = c("SymptomName")
#trimws returns a character string with leading and/or trailing whitespaces removed.
AllSymptoms$SymptomName = trimws(AllSymptoms$SymptomName)
AllSymptoms %>%
group_by(SymptomName) %>%
summarise(Count = n()) %>%
arrange(desc(Count)) %>%
ungroup() %>%
mutate(SymptomName = reorder(SymptomName,Count)) %>%
head(10) %>%
ggplot(aes(x = SymptomName,y = Count)) +
geom_bar(stat='identity',colour="white", fill = fillColor) +
geom_text(aes(x = SymptomName, y = 1, label = paste0("(",Count,")",sep="")),
hjust=0, vjust=.5, size = 4, colour = 'black',
fontface = 'bold') +
labs(x = 'Symptom',
y = 'Count',
title = 'Symptom and Count') +
coord_flip() +
theme_bw()
}
BarPlotSymptoms(AdverseFoodEvents)