Please help:
I am using qplot as below and want to specify a different color scheme for race
but dont know how, can someone show me.
Thanks in advance
Code and input file below:
library(ggplot2)
library(gridExtra)
d<-read.table("results", header=TRUE, fill=TRUE)
plot2<-qplot(X,Y,data=d,color=race,facets=TYPE~., xlab="X",
ylab="Y") + theme_bw()
grid.arrange(plot2,ncol=1)
dev.off()
cat? results
<snip>
X?????? Y?????? ID????? race??? TYPE
0.0350? 0.0200??? 1??? X??? NA
0.0280? 0.0251??? 2??? X??? NA
0.0258? 0.0175????3??? Y??? NA
</snip>
Hi David, I believe you left out saying what color scheme you would prefer, so it's hard to help, but you might be a start by looking at the appropriate parts of Hadley's website here: http://had.co.nz/ggplot2/, particularly the "scales" section. Best, Michael On Wed, Jun 27, 2012 at 11:07 AM, David Lyon <david_lyon3 at yahoo.com> wrote:> > > Please help: > > > I am using qplot as below and want to specify a different color scheme for race but dont know how, can someone show me. > > > Thanks in advance > > > > Code and input file below: > > > > library(ggplot2) > library(gridExtra) > d<-read.table("results", header=TRUE, fill=TRUE) > plot2<-qplot(X,Y,data=d,color=race,facets=TYPE~., xlab="X", ylab="Y") + theme_bw() > grid.arrange(plot2,ncol=1) > dev.off() > > > cat results > <snip> > X Y ID race TYPE > 0.0350 0.0200 1 X NA > 0.0280 0.0251 2 X NA > 0.0258 0.0175 3 Y NA > </snip> > > ______________________________________________ > 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.
Something like this may do it. http://stackoverflow.com/questions/6919025/how-to-assign-colors-to-categorical-variables-in-ggplot2-that-have-stable-mappin John Kane Kingston ON Canada> -----Original Message----- > From: david_lyon3 at yahoo.com > Sent: Wed, 27 Jun 2012 09:07:53 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] qplot and colors (Please Help) > > > > Please help: > > > I am using qplot as below and want to specify a different color scheme > for race but dont know how, can someone show me. > > > Thanks in advance > > > > Code and input file below: > > > > library(ggplot2) > library(gridExtra) > d<-read.table("results", header=TRUE, fill=TRUE) > plot2<-qplot(X,Y,data=d,color=race,facets=TYPE~., xlab="X", ylab="Y") + > theme_bw() > grid.arrange(plot2,ncol=1) > dev.off() > > > cat? results > <snip> > X?????? Y?????? ID????? race??? TYPE > 0.0350? 0.0200??? 1??? X??? NA > 0.0280? 0.0251??? 2??? X??? NA > 0.0258? 0.0175????3??? Y??? NA > </snip> > > ______________________________________________ > 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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
colors <- c("red", "blue", "darkgreen",
"gold", "black")
labels <-
c("3/02/2012","12/30/2011","4/20/2012")
In plot I use
{
plot(x, hx1 , type="l", lwd=2, tck=1, col=colors[1], ylim=c(0, maxhx),
xlab="x value", ylab="Density", main="AAPL")
.
.
.
labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
}
It looks like qplot uses
colour=colors
to pickup colors.
At the R console type
colors()
For a list of color names and numbers.
Hope this helps.
Frank
Chicago, IL
> Date: Wed, 27 Jun 2012 09:07:53 -0700
> From: david_lyon3@yahoo.com
> To: r-help@r-project.org
> Subject: [R] qplot and colors (Please Help)
>
>
>
> Please help:
>
>
> I am using qplot as below and want to specify a different color scheme for
race but dont know how, can someone show me.
>
>
> Thanks in advance
>
>
>
> Code and input file below:
>
>
>
> library(ggplot2)
> library(gridExtra)
> d<-read.table("results", header=TRUE, fill=TRUE)
> plot2<-qplot(X,Y,data=d,color=race,facets=TYPE~., xlab="X",
ylab="Y") + theme_bw()
> grid.arrange(plot2,ncol=1)
> dev.off()
>
>
> cat results
> <snip>
> X Y ID race TYPE
> 0.0350 0.0200 1 X NA
> 0.0280 0.0251 2 X NA
> 0.0258 0.0175 3 Y NA
> </snip>
>
> ______________________________________________
> R-help@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.
[[alternative HTML version deleted]]