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")
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-10-13 11:00:00 +0000
Seen: 10 times
Last updated: Oct 31 '22
Can a matplotlib boxplot be created using percentile values in place of the original inputs?
How can you create an OpenGL plot without relying on external libraries, starting from scratch?
How can I use iText7 to create a PDF that includes a pie chart?
How can I create a monitor in Datadog that includes multiple resources' metrics in one monitor?
Create a regular expression for the following format.
How to create GS1-128 using ZXing.Net?
Is it advisable to create event handlers in a separate method rather than inline all the time?