0

How is it possible to create a box plot like this

data.frame(category = c(2, 3, 3, 3, 2, 2, 3, 3, 3, 3, 2, 3, 1, 3), educational_years = c(6, 15, 16, 6, 6, 6, 12, 12, 12, 4, 12, 15, 6, 4), gender = c("M", "F", "F", "F", "M", "M", "F", "M", "F", "F", "M", "F", "M", "F"))

from a data frame like this and x axis have the category y axis age and factor gender

1
  • How is this different from your question from a half hour ago? If you have additional information to add, you should edit the previous one. Just like in that question, this should include a clear example of what you're asking for and what you've tried Commented Mar 1, 2022 at 17:34

1 Answer 1

1

You don't have enough data to create a boxplot like the one shown. For example, you only have a single data point for category 1, so you will only get a single horizontal line here. You only have "M" values for category 2, so you will only get a single box here. You have only a single value for "M" in category three, so you will get a horizontal line instead of a box.

Assuming this is only a sample of your data, rather than the full data set, the code would look like this:

library(ggplot2)

ggplot(df, aes(factor(category), educational_years, fill = gender)) + 
  geom_boxplot()

At the moment, the result obtained looks like this:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.