[R] scatter plot using ggplot

hadley wickham h.wickham at gmail.com
Tue Jul 22 18:30:13 CEST 2008


On Tue, Jul 22, 2008 at 3:42 AM, Megh Dal <megh700004 at yahoo.com> wrote:
> I used ggplot to create a scatter plot :
>
> library(ggplot)
> library(mnormt)
> Sigma = matrix(c(1, 0.6, 0.6, 1), 2, 2)
> x = rmnorm(20, c(0,0), Sigma)
> xx = x[order(x[,1]),]
> y = xx[,1]
> z = xx[,2]
> qplot(z, y, type="point", main="x-y plot", xlab="x", col="blue")
>
> However I want following:
>
> 1. Plot color must be Blue (where it is displaying as red)
> 2. There should not be any color platted

You can't currently do this with qplot (but will be able to in the
next version).  Use ggplot() instead:

ggplot(data.frame(y,z), aes(y, z)) +
geom_point(colour = "blue") +
scale_x_continuous("x") +
opts(title = "x-y plot")

> 3. Plot size must be larger than what it is displacing

Make the window bigger?

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list