2

I am attempting to create several histograms that display the effects a drug has on the frequency of heart attacks.

Currently, R is organizing my data into the bins [0 - 0.5, 0.5 - 1.0, 1.0 - 1.5, etc.], but I would like for it to only use integer values: [0 - 1, 1 - 2, 2 - 3, etc.].

I have tried using the xaxt="n" argument and the axis() function. They "worked," but they did not solve the problem above. I also tried to use breaks=seq(0,5,l=6), but this converted my y-axis from frequency into density.

Here is the code for my latest two attempts:

hist(fourTrials$red_5, breaks=5, right = FALSE, 
      xlab = "Number of Heart Attacks", 
      xlim = c(0, 4), ylim = c(0,4), 
      main = "Experimental Group 1, n = 400", col = "light blue")

hist(fourTrials$red_5, breaks=seq(0,5,l=6), freq = F, right = FALSE, 
      xlab = "Number of Heart Attacks", 
      xlim = c(0, 4), ylim = c(0,4), 
      main = "Experimental Group 1, n = 400", col = "light blue",yaxs="i",xaxs="i")

In this image, I want the bars to occupy the whole bin space. For example, the third bar should occupy the 2-3 bin.

Thanks for any help!

G5W
  • 36,531
  • 10
  • 47
  • 80
Guy Cerretti
  • 21
  • 1
  • 2
  • Could you please provide your data by typing `dput(fourTrials)` and pasting the result into your question? – G5W Feb 05 '17 at 01:53

1 Answers1

2

I believe that what you want is:

hist(fourTrials$red_5, breaks=0:4, freq = TRUE, right = FALSE, 
    xlab = "Number of Heart Attacks", 
    xlim = c(0, 4), ylim = c(0,4), 
    main = "Experimental Group 1, n = 400", 
    col = "lightblue", yaxs="i", xaxs="i")
G5W
  • 36,531
  • 10
  • 47
  • 80