5

When I try to visualize my integer data with histogram(mydata,breaks=c(0,n)), R usually doesnt care about how many breaks (usually 1 bar for each sample) do I use and it plots n-1 bars (first two bars are summed into one).

In most cases I use barplot(table(mydata))

And there is one more way to do it How to separate the two leftmost bins of a histogram in R but I think its not "clear" way.

So how do you visualize frequency of your integer data? Which one is right?

Thank you a lot

Community
  • 1
  • 1
user1991825
  • 309
  • 1
  • 5
  • 16

1 Answers1

14
hist(dataset, breaks=seq(min(dataset)-0.5, max(dataset)+0.5, by=1)  )

Another option (for thos situations where you know these are integers would be:

require(lattice) 
barchart(table(dataset), horizontal=FALSE)

Or:

barplot(table(dataset))
IRTFM
  • 258,963
  • 21
  • 364
  • 487