[R] boxplot of different colors

John Kane jrkrideau at inbox.com
Wed Sep 26 18:23:37 CEST 2012


Shamelessly stealling Richard Heiberger's data set I'd suggest another way using ggplot2 which you would need to install

library(ggplot2)

dataN <- data.frame(GE_distance=rnorm(260),
                    Diet_B=factor(rep(1:13, each=20)))

p  <-  ggplot(dataN , aes(Diet_B, GE_distance, colour = Diet_B  )) + geom_boxplot() +
       xlab("Migration") + ylab("Distance")
p 


John Kane
Kingston ON Canada


> -----Original Message-----
> From: rmh at temple.edu
> Sent: Mon, 24 Sep 2012 19:00:09 -0400
> To: elaine.kuo.tw at gmail.com
> Subject: Re: [R] boxplot of different colors
> 
> ## I would do this in lattice using the panel.bwplot.intermediate.hh
> ## function from the HH package.
> 
> ## install.packages("HH") ## if necessary
> library(HH)
> 
> dataN <- data.frame(GE_distance=rnorm(260),
>                     Diet_B=factor(rep(1:13, each=20)))
> Diet.colors <- c("forestgreen", "darkgreen","chocolate1","darkorange2",
>                  "sienna2","red2","firebrick3","saddlebrown","coral4",
>                  "chocolate4","darkblue","navy","grey38")
> bwplot(GE_distance ~ Diet_B, data=dataN,
>        xlab=list("Diet of Breeding Ground", cex = 1.4),
>        ylab = list(
>          "Distance between Centers of B and NB Range (1000 km)",
>          cex = 1.4),
>        panel=panel.bwplot.intermediate.hh,
>        col=Diet.colors,
>        pch=rep("|",13))
> 
> 
> On Mon, Sep 24, 2012 at 6:23 PM, Elaine Kuo <elaine.kuo.tw at gmail.com>
> wrote:
> 
>> Hello,
>> 
>> I am making a boxplot of 13 boxes.
>> I tried to color the box using 13 colors but failed.
>> Only red and brown were displayed.
>> Green, blue, and grey disappeared.
>> 
>> Please kindly advise modification after checking the code below.
>> Thank you in advance.
>> 
>> Elaine
>> 
>> R code
>> # data input
>>     dataN
>> 
>> <-read.csv("H:/a_mig_distance_B_NB/R_data/Mig_bird_586_20120925.csv",header=T,
>> row.names=1)
>>     dim(dataN)
>>     dataN[1,]
>>     str(dataN)
>> 
>>   # graph
>>     par(mai=c(1,1.03,0.4,0.4))
>> 
>>     obs.group<-dataN$Diet_B
>> 
>>     par(new=T)
>> 
>>     boxplot(GE_distance~Diet_B, data=dataN,xlab="Diet  of  Breeding
>>  Ground",ylab="",
>>     yaxt="n",type="p",
>>     pch=1,lwd=0.95,
>>     cex.lab=1.4, cex.axis=1.2,
>>     font.axis=2,
>>     cex=1.5,
>>     las=1,
>>     bty="l",
>>     col=c("forestgreen",
>> "darkgreen","chocolate1","darkorange2","sienna2",
>> "red2","firebrick3",
>> 
>> 
>> "saddlebrown","coral4","chocolate4","darkblue","navy","grey38")[obs.group]))
>> 
>>     op = par(mar = c(5,5,4,2) + 0.1)
>>     title(ylab = "Distance between Centers of B and NB Range (1000 km)",
>> cex.lab = 1.4,line = 3)
>> 
>>     axis(side=2,yaxp=c(0,20000,4),cex.lab=1.4, cex.axis=1.2,font.axis=2,
>> las=1)
>> 
>>         [[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.
>> 
> 
> 	[[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.

____________________________________________________________
Send any screenshot to your friends in seconds...
Works in all emails, instant messengers, blogs, forums and social networks.
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if2 for FREE




More information about the R-help mailing list