how to create a frequency histogram with preset non-uniform intervals?

Asked

Viewed 90 times

1

How can I make a histogram on Rstudio with the frequency on the y-axis and on the x-axis non-uniform predefined intervals, for example: 0-50, 50-150, 150-500, 500-2000.

I have a hypothetical date.frame as I would not like to share my original data.

dados <- c(1,1.2,40,1000,36.66,400.55,100,99,2,1500,333.45,25,125.66,141,5,87,123.2,61,93,85,40,205,208.9).

1 answer

2

Basically, just use the argument breaks custom. For example, using R pattern:

dados <- c(1, 1.2, 40, 1000, 36.66, 400.55, 100, 99, 2, 1500, 333.45, 
  25, 125.66, 141, 5, 87, 123.2, 61, 93, 85, 40, 205, 208.9)

hist(dados, breaks = c(0, 50, 150, 500, 2000), freq = TRUE)

inserir a descrição da imagem aqui

Using ggplot2:

library(ggplot2)

dados <- as.data.frame(dados)

ggplot(dados, aes(x = dados)) +
  geom_histogram(breaks = c(0, 50, 150, 500, 2000))

inserir a descrição da imagem aqui

  • your idea was pretty good, but how do I get it to stay with bars of equal size but custom interval?

  • 1

    What do you mean? What is "size"? Is the width of the bar? And if it’s the width of the bar, how could they look the same if the ranges have different sizes?

  • This as the bars would be equal considering that the intervals are equal.

  • This comment makes no sense. I still don’t understand how my chart could be different considering what was asked in the original question.

  • is that I thought I could make a chart where the bars would be the same width, but with different x-axis intervals. It would be possible?

  • It’s possible, but it won’t be a histogram. Histograms are frequency distribution graphs, the area (height and width) should be proportional to the data.

  • understood Carlos, how I could do this, because I would like to know the frequency that a certain value is within a certain value, I think I’m half lost to a graph so simple rsrsrs.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.