Números en la esquina de su barra en un histograma, ¿cómo puedo centrarlos debajo de la barra?

I'm drawing a histogram with the standard hist function with this example dataset:

v= c(0L, 0L, 0L, 1L,1L,1L,2L, 2L, 2L,4L, 4L, 4L)
hist(v, main='example', xlab='example', ylab='example', breaks=5)

The problem that I'm having is that the hist picture looks like this

| ___
||   |
||   |___     ___ 
||   |   |   |   |
||___|___|___|___|
 0   1   2   3   4

So because the 0 starts at the corner, the 0 and 1 bar are combined, and the bar of 2 and 4 looks like it belongs to 1 and 2, 3 and 4. What I want to have is

| 
|   
| ___ ___ ___     ___
||   |   |   |   |   |
||___|___|___|___|___|
   0   1   2   3   4

I tried by changing the breaks, but that does not solve the problem of the numbers being at the corner. How can I get the numbers to be centered under the bars?

preguntado el 09 de marzo de 12 a las 14:03

Shouldn't the histogram have a bar for 3 as well? -

A histogram is supposed to have the labels at the breaks. The plotted area is the number of values between the breaks. If you want a barplot then use barplot. -

@Hudson I accidentaly put the wrong vector in as example, changed it now -

1 Respuestas

Quizás deberías usar ?barplot en vez.

v = c(0L, 0L, 0L, 1L,1L,1L,2L, 2L, 2L, 3L,3L,3L,4L, 4L, 4L)
barplot(table(v))

respondido 09 mar '12, 14:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.