unixsnob
unixsnob

Reputation: 1705

R - Scatter plots, how to plot points in differnt lines to overlapping?

I want to plot several lists of points, each list has distance (decimal) and error_no (1-8). So far I am using the following:

plot(b1$dist1, b1$e1, col="blue",type="p", pch=20, cex=.5)
points(b1$dist2, b1$e2, col="blue", pch=22)

to add them both to the same plot. (I will add legends, etc later on).

The problem I have is that points overlap, and even when changing the character using for plotting, it covers up previous points. Since I am planning on plotting a lot more than just 2 this will be a big problem.

I found some ways in:

http://www.rensenieuwenhuis.nl/r-sessions-13-overlapping-data-points/

But I would rather do something that would space the points along the y axis, one way would be to add .1, then .2, and so on, but I was wondering if there was any package to do that for me.

Cheers M ps: if I missed something, please let me know.

Upvotes: 0

Views: 6739

Answers (3)

Greg Snow
Greg Snow

Reputation: 49640

Look at the spread.labs function in the TeachingDemos package, particularly the example. It may be that you can use that function to create your plot (the examples deal with labels, but could just as easily be applied to the points themselves). The key is that you will need to find the new locations based on the combined data, then plot. If the function as is does not do what you want, you could still look at the code and use the ideas to spread out your points.

Another approach would be to restructure your data and use the ggplot2 package with "dodging". Other approaches rather than using points several times would be the matplot function, using the col argument to plot with a vector, or lattice or ggplot2 plots. You will probably need to restructure the data for any of these.

Upvotes: 0

Carl Witthoft
Carl Witthoft

Reputation: 21502

Depends a lot on what information you wish to impart to the reader of your chart. A common solution is to use the transparency quality of R's color specification. Instead of calling a color "blue" for example, set the color to #0000FF44 (Apologies if I just set it to red or green) The final two bytes define the transparency, from 00 to FF, so overlapping data points will appear darker than standalone points.

Upvotes: 2

nograpes
nograpes

Reputation: 18323

As noted in the very first point in the link you posted, jitter will slightly move all your points. If you just want to move the points on the y-axis:

plot(b1$dist1, b1$e1, col="blue",type="p", pch=20, cex=.5)
points(b1$dist2, jitter(b1$e2), col="blue", pch=22)

Upvotes: 2

Related Questions