0

I am working on a diametric class distribution data, with over 10,000 individuals, and I wanted to make a histogram to show the results, but I am having a problem when I try to plot it. When I tried using the histogram function

histogram(data)

I get a histogram that is calculating the percentage of individuals

Histogram using the histogram function

Then I tried using qplot function

qplot(data, geom = "histogram")

And got a histogram like the one you can see in image 2

qplot function

So I thought maybe is a problem with the y-axis scale so I tried using ylim() and the plot I got was only the axis with no data

Could someone please tell me what I'm doing wrong?

I'm trying to get a histogram like the one in image 3Histogram goal

I really appreciate your help to point out if I am not adding other codes or maybe redirect me to a cheat sheet that can clarify some things

thanks

  • Can you post a [minimum reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? Post some small sample of your data and the expected output given that input :) – digEmAll Aug 04 '18 at 08:26
  • Have you adjusted the bins in your histograms? Different functions might have different ways of selecting default numbers of bins, and how a histogram looks and how you might read it at first glance depends a lot on how the data is binned – camille Aug 04 '18 at 13:57

1 Answers1

0

Try to use the ggplot2 package, for example:

library(ggplot2)
ggplot(data = [YOUR_DATA], aes([YOUR_VARIABLE])) + 
  geom_histogram()

EDIT:

Looking at your desired result, I think you want to use barplot() instead of histogram().

Stan
  • 480
  • 1
  • 5
  • 18
  • @GonzalodeQuesada did you check my edit? I am unsure what you want as a result exactly but you can try to use `barplot()` as well. Although `ggplot()` is very useful to edit your plot more than just the basics. – Stan Aug 04 '18 at 08:21
  • @GonzalodeQuesada I would appreciate it if you will accept my answer if it worked out for you :). – Stan Aug 04 '18 at 08:23