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

baptiste auguie ba208 at exeter.ac.uk
Sun Apr 26 13:57:14 CEST 2009


Hi,

You could do this very easily using ggplot2,

> #install.packages("ggplot2", dep=TRUE)

> library(ggplot2)
>  c <- ggplot(mtcars, aes(y=wt, x=mpg)) + facet_grid(. ~ cyl)
>  c + stat_smooth(method=lm) + geom_point()

See more examples on Hadley's website: http://had.co.nz/ggplot2/

Hope this helps,

baptiste


On 26 Apr 2009, at 10:29, 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).
>
> I'm greatful for every (simple) solution
> Thanks in advance
>
> Karin Schneeberger
> MSc-student
> University of Berne
> Switzerland
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag




More information about the R-help mailing list