0

I want to create a histogram in R. My code is:

hist(P1_Pre_Benefits, main="Pre survey Benefits", xlab="", 
     col="lightgreen", breaks=c(0.5,1.5, 2.5, 3.5, 4.5, 5.5), xaxt="n", xlim=c(1, 6), ylim=c(0, 45))

 axis(side=1, at=seq(1, 5, 1), 
      labels=c("1", "2", "3", "4", "5"))

This works, however, the first bar is too close to the y axis, I would like a space here. Anyone know how to solve this?

current output

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Saskia
  • 1
  • 2
    Try `xlim=c(0, 6)`. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 16 '23 at 13:57
  • Also, are you only interested in base R answers, or would answers using other packages, like ggplot2, be acceptable? – divibisan Jun 16 '23 at 14:02
  • Thank you so much, that was so easy to solve! – Saskia Jun 16 '23 at 14:04

0 Answers0