1
library(ggplot2)
data <- c(1,0,1,1,0)
qplot(data) + geom_bar() + labs(x="Merged", y="Count")

this generates:

enter image description here

However, I wanted to generate a boxplot, and have no use for the values 0.25, 0.50, and 0.75 since they cannot exist in this data. I simply want two bars for 0 and 1 indicating the count of each value in the dataset. How can I accomplish this?

1
  • Looks like you mean barplot, rather than boxplot. Commented Jun 8, 2016 at 15:52

1 Answer 1

5
library(ggplot2)
data <- c(1,0,1,1,0)
qplot( as.factor(data) ) + 
    geom_bar() + 
    labs(x="Merged", y="Count")

This is based on @aosmith observation that a factor will remove the ordinality of the data, and the @eipi10 observation that you're looking for a barplot, not a boxplot.

Yields boxplot

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.