Question: I want to create a scatterplot in ggplot where there are multiple y values for each x value. I want to add these y values and plot the sum against the x value.

```
>df
a b
1 2
1 2
2 1
2 4
3 1
3 5

```

I want a plot that plots the sums of the b values for each a

```
a b
1 4
2 5
3 6

```

I can do this for a barplot by making a stacked barplot:
`ggplot(data=df, aes(x=df$a, y=df$b)) + geom_bar(stat="identity")`

but if I do this with geom\_point ggplot just plots each value of y without stacking.

I could use ddply for this, but that would require a number of more steps. If there is a more expedient way I'd appreciate it.

I searched the site for other answers. While there were plenty about "stacked scatterplots" they were all about overlaid plots.

Answer: 
I don't see anything stacked about your bar chart example. If you just want to summarize the values to a single pont, you can use `stat_summary`

```
ggplot(data=df, aes(x=a, y=b)) + stat_summary(fun.y=sum, geom="point")

```
There are many ways to achieve this effect - of a 'histogram' but without bars, whose height is the sum of all values at the same X.

This type of graph is called a Cleveland Dot Plot, and is used because the conspicuous bars of a histogram can a distraction or at worse be misleading. (see works by Cleveland, Tufte etc). 

One way to achieve this is to pre-process the data to do the sum, using functions such as `table` or `hist` or `tapply` or `xtabs`...

Note that base R has the function `dotchart` for the production of this type of graph.

```
dotchart(xtabs(rev(df)))

```

[![enter image description here](https://i.stack.imgur.com/x47an.png)](https://i.stack.imgur.com/x47an.png) 

... but since we are discussing `ggplot`, which has powerful ways to summarise the data *while plotting it*, let's stick to MrFlick's theme of how to do it directly ggplot operators (i.e. not preprocessed).

Using a weighted bin summary statistic:
---------------------------------------

```
ggplot(data=df, aes(x=factor(a),weight=b)) + geom_point(stat="bin")

```

[![enter image description here](https://i.stack.imgur.com/QeLFd.png)](https://i.stack.imgur.com/QeLFd.png)

you may want to adjust the lower y limit to 0 here.

By stacking the height of the points:
-------------------------------------

```
ggplot(data=df, aes(x=factor(a),y=b)) + geom_point(position="stack")

```

[![enter image description here](https://i.stack.imgur.com/GgTST.png)](https://i.stack.imgur.com/GgTST.png)

the additional dots visible on this plot are probably superfluous and definitely ambiguous, but highlight the fact of multiplicity in the source data.

Building a dotplot
------------------

This one is popular in newspapers, but usually has dollar bills instead of giant black holes:

ggplot(data=df, aes(x=factor(a),weight=b)) + geom\_dotplot(method="histodot")

[![enter image description here](https://i.stack.imgur.com/67HsP.png)](https://i.stack.imgur.com/67HsP.png)

It's probably not what you are looking for, but it's worth being aware of.

You should also be aware that scales are difficult to get correct in this mode, so it's best used in a hand-tuned mode, with the y scale numbering turned off.