1 | initial version |
Assuming you have a dataset with two columns: sex and diagnosis level, you can use the following code to create either a boxplot or a barplot:
library(ggplot2)
sex <- c("Male", "Male", "Male", "Female", "Female", "Male", "Female", "Female", "Male", "Male") diagnosis <- c("Level 1", "Level 2", "Level 1", "Level 1", "Level 2", "Level 1", "Level 2", "Level 2", "Level 2", "Level 1") df <- data.frame(sex, diagnosis)
ggplot(df, aes(x = diagnosis, y = sex)) + geom_boxplot() + ylab("Sex") + xlab("Diagnosis Level")
ggplot(df, aes(x = diagnosis, fill = sex)) + geombar(position = "dodge") + ylab("Frequency") + xlab("Diagnosis Level") + scalefill_manual(values = c("blue", "pink"), name = "Sex")