I am simply trying to produce a bar plot (with ggplot) where both plan_preg and plan_wanted are on the same graph (as two separate groups) representing their counts of yes and no's.
df <- structure (list(subject_id = c("191-5467", "191-6784", "191-3457", "191-0987", "191-1245",
"191-2365", "191-4532", "191-9901", "191-2710"),
plan_preg = c("Yes","No","No","No","Yes","No", "NA", "Yes", "Yes"),
plan_wanted = c("Yes","No","Yes","Yes","NA","No","NA", "Yes", "No")),
class = "data.frame", row.names = c (NA, -9L))
What I've tried:
df_long <- tidyr::pivot_longer(df, cols=-1)
ggplot(preg_long, aes(x = name, y = factor(value), fill = name)) + # specify x and y axis, specify fill
geom_col(position = position_dodge(0.7), width = 0.6, color = "black") + # position.dodge sets the bars side by side
theme_minimal()