New to R, apologies in advance. I have run the following code to get separate plots showing the percentage of proportion of Injury_Areas for each Occupation_Proper.
SelectOccupation_InjuryAreas %>%
group_by(Occupation_Proper) %>%
mutate(prop = counnt / sum(counnt)) %>%
ggplot(aes(Injury_Area, prop)) +
ylab('prop') +
geom_bar(stat="identity") +
scale_y_continuous(labels=percent) +
facet_wrap(~ Occupation_Proper,ncol=2)+
geom_col(aes(fill = Occupation_Proper), position = "dodge") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
geom_text(aes(label = scales::percent(prop),
y = prop,
group = Occupation_Proper),
position = position_dodge(width = 0.9),
vjust = 1.5)
I would like to show the percentage of each Injury_Area as a percentage of the total of all Injury_Area for each Occupation_Proper separately. The code that I ran for some reason is displaying the Injury_Area percentages as a percentage of all of the plots combined instead of displaying the percentages for each plot separately (e.g. percentage for each plot separately should add up to 100), see picture of plots 1. How do I get percentages of proportions for each plot separately? Thank you!
My data is as follows (using R Studio so hopefully this is the correct way to display.
structure(list(Occupation_Proper = c("HTO", "HTO", "HTO", "HTO",
"HTO", "HTO", "HTO", "HTO", "HTO", "HTO", "HTO", "HTO", "HTO",
"HTO", "HTO", "HTO", "HTO", "HTO", "Bl", "Bl", "Bl", "Bl", "Bl",
"Bl", "Bl", "Bl", "Bl", "Bl", "Bl", "Cb", "Cb", "Cb", "Cb", "Cb",
"Cb", "Cb", "Cb", "Cb", "Cb", "Cb", "Cb", "CrO", "EO", "EO",
"EO", "EO", "EO", "EO", "EO", "EO", "EO", "EO", "EO", "EO", "EO",
"EO", "EO", "L", "L", "L", "TR", "TR", "TR", "TR", "TR", "TR",
"TR", "TR", "WH", "WH", "WH", "WH", "WH", "WH", "WH", "WH", "WH",
"WH", "WH", "WH"), Injury_Area = c("Back", "Neck", "Hand", "Head",
"Face", "Arm", "Leg", "Foot", "Knee", "Chest", "Eye", "Ear",
"Ribs", "Throat_Tongue", "Other", "Hip", "Buttock_Pelvis", "Torso",
"Neck", "Hand", "Head", "Arm", "Leg", "Knee", "Eye", "Ear", "Other",
"Hip", "Torso", "Neck", "Hand", "Head", "Arm", "Leg", "Foot",
"Knee", "Eye", "Other", "Hip", "Buttock_Pelvis", "Torso", "Knee",
"Neck", "Hand", "Head[", "Face", "Arm", "Leg", "Foot", "Knee",
"Torso_Buttock", "Eye", "Ear", "Spill", "Other", "Buttock_Pelvis",
"Torso", "Arm", "Eye", "Other", "Neck", "Hand", "Face", "Arm",
"Knee", "Eye", "Ear", "Hip", "Hand", "Head", "Face", "Arm", "Leg",
"Knee", "Eye", "Ear", "Other", "Hip", "Buttock_Pelvis", "Torso"
), counnt = c(4, 30, 20, 17, 15, 18, 32, 6, 13, 5, 12, 9, 2,
3, 50, 5, 6, 3, 2, 1, 1, 2, 7, 7, 1, 2, 2, 1, 1, 4, 7, 2, 5,
16, 1, 5, 1, 2, 3, 1, 2, 2, 14, 18, 6, 7, 19, 14, 3, 6, 1, 5,
4, 2, 26, 1, 2, 1, 1, 1, 1, 11, 2, 7, 1, 1, 5, 1, 12, 1, 3, 8,
2, 1, 2, 2, 2, 1, 1, 1)), row.names = c(NA, -80L), class = "data.frame")
