[R] FW: plot legend outside the grid

Ghosh, Sandeep sghosh at lexgen.com
Fri Jul 1 00:55:32 CEST 2005



-----Original Message-----
From: Ghosh, Sandeep 
Sent: Thursday, June 30, 2005 5:43 PM
To: 'Berton Gunter'
Subject: plot legend outside the grid 


Thanks for the pointers... I managed to get everything to look and feel the way I want except for the legend to plot outside the grid... Thanks for the note on the par, but I'm not able to it to plot outside the plot grid..

dataFrame <- as.data.frame(t(structure(c(
64,'wt',
62,'wt',
66,'wt',
65,'wt',
60,'wt',
61,'wt',
65,'wt',
66,'wt',
65,'wt',
63,'wt',
67,'wt',
65,'wt',
62,'wt',
65,'wt',
68,'wt',
65,'wt',
63,'wt',
65,'wt',
62,'wt',
65,'wt',
66,'wt',
62,'wt',
65,'wt',
65,'wt',
66,'wt',
65,'wt',
62,'wt',
65,'wt',
66,'wt',
65,'wt',
61,'wt',
65,'wt',
66,'wt',
65,'wt',
62,'wt',
63,'het',
67,'het',
60,'het',
67,'het',
66,'het',
62,'het',
65,'het',
62,'het',
61,'het',
62,'het',
66,'het',
60,'het',
65,'het',
65,'het',
61,'het',
64,'het',
68,'het',
64,'het',
63,'het',
62,'het',
64,'het',
62,'het',
64,'het',
65,'het',
60,'het',
65,'het',
70,'het',
63,'het',
67,'het',
66,'het',
65,'hom',
62,'hom',
68,'hom',
67,'hom',
67,'hom',
63,'hom',
67,'hom',
66,'hom',
63,'hom',
72,'hom',
62,'hom',
61,'hom',
66,'hom',
64,'hom',
60,'hom',
61,'hom',
66,'hom',
66,'hom',
66,'hom',
62,'hom',
70,'hom',
65,'hom',
64,'hom',
63,'hom',
65,'hom',
69,'hom',
61,'hom',
66,'hom',
65,'hom',
61,'hom',
63,'hom',
64,'hom',
67,'hom'), .Dim=c(2,98))));

colnames(dataFrame) <- c('marbles_buried', 'genotype');

png('mb.png', width=400, height=400, pointsize=8);

dataFrame[c("marbles_buried")] <- lapply(dataFrame[c("marbles_buried")], function(x) as.numeric(levels(x)[x]));

par(xpd=FALSE)

with (dataFrame, stripchart(marbles_buried ~ genotype, method="jitter", vertical=TRUE,  col = c('blue', 'red', 'green'), xlab='Genotype', ylab = "Marbles Buried", main='MBA WTs Vs HOMs', pch=c(1,4,2), jitter=1/3.5, cex=1))

meds <- as.vector(with(dataFrame, by(marbles_buried, genotype, mean)))
segments((1:3)-0.25, meds, (1:3)+0.25, meds, col = c('blue', 'red', 'green'));

dataWt <- subset(dataFrame, genotype=='wt', select=c(marbles_buried,genotype));
dataHet <- subset(dataFrame, genotype=='het', select=c(marbles_buried,genotype));
dataHom <- subset(dataFrame, genotype=='hom', select=c(marbles_buried,genotype));

wtCount <- length(dataWt$marbles_buried);
hetCount <- length(dataHet$marbles_buried);
homCount <- length(dataHom$marbles_buried);
wtLegend <- paste ("wt, (n=", wtCount, ")");
hetLegend <- paste ("het, (n=", hetCount, ")");
homLegend <- paste ("hom, (n=", homCount, ")");

par(xpd=TRUE)
legend(1, max(as.vector(dataFrame$marbles_buried)), c(wtLegend, hetLegend, homLegend), col=c('blue', 'red', 'green'), pch=c(1,4,2));

-Thanks
Sandeep.

-----Original Message-----
From: Berton Gunter [mailto:gunter.berton at gene.com]
Sent: Thursday, June 30, 2005 2:55 PM
To: Ghosh, Sandeep
Subject: RE: [R] Help with stripplot


Of course!

stripchart() is a base graphics function and tehrefore has available to it
the base graphics functionality, like (the base graphics function, **not**
the lattice argument) legend(). See ?legend in the graphics package. Note
the use of locator() for positioning the legend.

Note: By default the legend will be clipped to the plot region. If you wish
to have a legend outside the plot region set the xpd parameter of par to
TRUE or NA prior to plotting.

-- Bert 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ghosh, Sandeep
> Sent: Thursday, June 30, 2005 12:22 PM
> To: Deepayan Sarkar; r-help at stat.math.ethz.ch
> Subject: Re: [R] Help with stripplot
> 
> Another question, in stripchart is there a way to draw a 
> legends. I need legends that gives the mice count for each 
> genotype wt/het/hom, something like the xyplot plot support 
> for key/auto.key.
> 
> -Sandeep




More information about the R-help mailing list