Generate two histograms starting from a vector (values >2.5 in a bar and values < 2.5 in the other one)

Hi! I'm very new with RStudio, I don't know how to solve this small problem, if anyone could help it would be great, thanks!

Basically I have a numeric vector with numbers between 0 and 5. I would like to get a plot showing two histagram bars; one containing all the values of the vector smaller than 2.5 and the other one containing the values bigger than 2.5.

I've tried with ggplot, but what I get every time is a plot with one bar for each number of the vector!
Thanks in advance :slight_smile:

universe <- seq(0,5,.1)
v <- sample(universe,100,replace = TRUE)
hist(v[v < 2.5])

hist(v[v > 2.5])

sum(v[v == 2.5])
#> [1] 5

Created on 2023-09-11 with reprex v2.0.2


  1. Make example reproducible
  2. Create fake vector
  3. Use the fake vector to draw a sample with replacement to make sure that there is a decent chance that values will be diffent
  4. Subset the vector based on which values meet the greater than/less than test using the positions that are TRUE
  5. See if anything is left over
  6. Plot
  7. See if anything is left over

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.