[R] automaticly adjust coordinates for text() labels

Sergey Goriatchev sergeyg at gmail.com
Wed Oct 17 12:43:02 CEST 2007


Hello,

I have following problem.

I produce a histogram of some values and in the plot area I create 2
text boxes - one with names of statistics and one with values of these
statistics. Coded like that:

ht <-hist(x, ....)
...
ameant <-ameant <- paste("Ar.Mean")
...
amean <- round(mean(x), digits=2)
...
text(min(ht$mids), seq(from=0.97*max(ht$density),
by=-0.05*max(ht$density), length.out=9),
        labels=c(ameant, amediant, mit, mat, stdevt, skewt, kurtt,
adt, jbt), pos=4, cex=0.7)

text(min(ht$mids)-0.4*min(ht$mids), seq(from=0.97*max(ht$density),
by=-0.05*max(ht$density), length.out=9),
        labels=c(amean, amedian, mi, ma, stdev, skew, kurt, ad, jb),
pos=4, cex=0.7)

so, there are 9 lines, each consisting of a name (placement specified
with first text command) and a value (placement specified with second
text command).

The problem is, that when the x-axis values change, the second part
sometimes crashes into first one. I tried to automate the placement of
the second part by using ht$mids, but this still does not work when
the values on x-axis change.

Maybe someone has a clever suggestion for the automatic placement of
he second text part so that it is close to first part never crashes
into it, and looks something like this:

Ar.Mean  0.50
Median    0.40
Std.Dev   8.32
...

Thanks in advance!
Sergey



More information about the R-help mailing list