Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot Histogram with Points Instead of Bars

Tags:

plot

r

histogram

Here is a question for R-users. I am interested in drawing a histogram with points stacked up, instead of a bar. For example if the data is (1,1,2,1,2,3,3,3,4,4), then I would like to see three points stacked up at 1, 2 points stacked up at 2 and so on. What is the best way to do this in R?

like image 425
Ramnath Avatar asked Dec 20 '09 03:12

Ramnath


People also ask

Why would someone make a histogram instead of a bar chart?

Histograms visualize quantitative data or numerical data, whereas bar charts display categorical variables. In most instances, the numerical data in a histogram will be continuous (having infinite values). Attempting to display all possible values of a continuous variable along an axis would be foolish.

How are histograms and bar plots different?

Histograms and bar charts can both display large sets of data. However, bar charts display categorical data, or information that's separated into different groups based on characteristics, while histograms display numerical or quantitative data in bins, which is data that you can measure with numbers.


2 Answers

You can do this yourself pretty quickly:

x <- c(1,1,2,1,2,3,3,3,4,4)
plot(sort(x), sequence(table(x)))
like image 153
Jonathan Chang Avatar answered Sep 20 '22 07:09

Jonathan Chang


The simplest answer I know is this:

x <- c(1,1,2,1,2,3,3,3,4,4)
stripchart(x,method="stack",at=0)

It's better than Jonathan Chang's suggestion because stripchart does proper stacking of points.

like image 34
Rob Hyndman Avatar answered Sep 19 '22 07:09

Rob Hyndman