[R] Scatterplot of two groups side-by-side?

Jim Lemon jim at bitwrit.com.au
Mon Apr 27 11:57:08 CEST 2009


nonunah at yahoo.de wrote:
> Dear all
>
> I'm realy new to R, so I hope you can help me, as I didn't find any solution in the common books.
>
> Since some days I'm trying to create the following plot: A scatterplott showning two different groups side-by-side with according regression lines. Both datasets only have the same five factors, so the scatters will form a kind of column at each factor. When I use "scatterplot" (package "car"), then I can plot two groups in the same graph by using the command "groups", but the scatters of both groups are then plotted on top of eachother using different symbols and they can hardly be distingushed. How can I plot them side by side, so that the groups do not overlap? And how can I give different colours to the groups and the according regression line?(This is, what I got so far: http://img7.imageshack.us/img7/227/almostgood.jpg)
>
> I tried to use the commands used in "boxplot", to solve this problem. In this commant, it's possible to plot different datasets side-by-side by defining the position of the bars (example: at = 1:5 - 0.4). A second boxplot-chart can then be added by adding the command "add=TRUE" to the line and defining another position. Both commands don't function within the scatterplot-command.
>
> By the way: It's realy necessary to plott the data as scatters and not as boxplots. With the command "plot", I can not plot the data by groups (I tried it with the commands "subset" and "groups", but obviously, there is no way to do so).
>
>   
Hi Karin,
I would use cluster.overplot in the plotrix package for the scattergram. 
This will adjust the positions of the points for the two groups so that 
they form little clusters instead of overplotting. You can color the two 
sets of points differently as well as use different symbols. Then by 
adding the two regression lines in the same two colors, you should have 
an easier to interpret plot.

Jim




More information about the R-help mailing list