In principle you are there, just after opening the device set par(mar) 
appropriate (large margin to place the legend in) before starting with 
plotting.
In the legend, specify points which virtually are in the margin you have 
already expanded...


Uwe Ligges



Ghosh, Sandeep wrote:

> 
> -----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',

[SNIP]


> 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:[EMAIL PROTECTED]
> 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: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf Of Ghosh, Sandeep
>>Sent: Thursday, June 30, 2005 12:22 PM
>>To: Deepayan Sarkar; r-help@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
> 
> 
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to