[R] Automatic anchors for text boxes
Greg Snow
Greg.Snow at intermountainmail.org
Fri Aug 31 18:59:33 CEST 2007
A couple of things that may help:
1. you can create your boxplots by using boxplot with plot=FALSE, then
plotting that info using the bxp function. The bxp function returns the
locations of the boxes as part of the output which could then be used
for placing labels or refrence lines.
2. The cnvrt.coords function in the TeachingDemos package will convert
between the different coordinate systems, so for instance if you want a
text box to be 80% of the way from the bottom to the top of the plot
region, you could convert the y coordinate of 0.8 from plot coordinates
to user coordinates and give the resulting value to the text function.
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Yves Moisan
> Sent: Friday, August 31, 2007 7:21 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Automatic anchors for text boxes
>
>
> Hi All,
>
> I'm struggling to add text automatically to plots. I have a
> series of scatterplots that I have stored in a script because
> the underlying data changes often and the plots need to be
> regenerated. I use the scatterplot function (defined in
> Rcmd, I believe). When one of the variables is a factor, a
> boxplot is drawn over the scatter of the other variable. In
> the case where x is a factor with 10 values, I'll see 10
> vertical boxplots. So far, so good.
>
> I was asked to show other stats on top of those scatterplots,
> e.g. mean, number of observations, etc. I can find those
> values, but the problem is I don't know how to put them on
> the plot, given I don't want to look at each plot one by one
> and manually identify the locations where I need to add the
> text. I was wondering if something like a pseudo label (I
> want to keep the original axis labels) existed that could be
> used to anchor a text box ? Or maybe a semi-manual approach
> where I could offset such a pseudo-label position along the y
> axis? Since I know the size of my resulting jpegs, I could
> use a constant y offset for the text and they'd be aligned properly
> along the x axis because they are labels. For the mean
> value, I could draw
> a short horizontal line segment across the boxplot, but again
> I'd have the problem of tying that line segment to specific
> x-axis values so they intersect the right boxplot. Any clues ?
>
> On a related note, I've added regression lines, again by
> factor (thanks scatterplot!), and was asked to write the
> regression equation in plain text.
> I have between one and 7 lines on the plots, so again how
> could I automatically tie a text box, this time to a specific
> regression line ?
> Maybe that would be easier using a legend, but it would be
> nice to be able to write the equation alongside the line.
>
> TIA
> --
> View this message in context:
> http://www.nabble.com/Automatic-anchors-for-text-boxes-tf43601
> 08.html#a12426263
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list