An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071203/678cd62c/attachment.pl
overlapping labels
5 messages · Biscarini, Filippo, jim holtman, Duncan Murdoch +2 more
You might look at 'jitter' to add a little offset to the labels being plotted.
On Dec 3, 2007 9:21 AM, Biscarini, Filippo <Filippo.Biscarini at wur.nl> wrote:
Good evening,
I am trying to add labels to the point of a simple plot, using the
text() function; the problem is that sometimes, if two points are too
close to each other, labels overlap and are no longer readable.
I was wondering whether there are options that I can use to prevent this
overlapping (by, for example, placing labels alternatively above and
below the plotted curve), or whether I should use another set of
graphical functions (grid or lattice packages).
Does anybody have suggestions?
Thank you,
Filippo Biscarini
PS: These are the lines of codes that I have been using to generate the
plot.
plot(
prova$x,
prova$y,
type="b",
mar=c(0.5,0.5,0.5,0.5),
xlab="basepairs",
ylab=""
);
text(
prova$x,
prova$y,
prova$lab,
pos=3,
offset=2,
cex=0.5
);
[[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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
On 12/3/2007 12:21 PM, Biscarini, Filippo wrote:
Good evening, I am trying to add labels to the point of a simple plot, using the text() function; the problem is that sometimes, if two points are too close to each other, labels overlap and are no longer readable. I was wondering whether there are options that I can use to prevent this overlapping (by, for example, placing labels alternatively above and below the plotted curve), or whether I should use another set of graphical functions (grid or lattice packages). Does anybody have suggestions?
I don't think there are any functions to automatically avoid overlaps,
but it is not hard to manually move some of the labels. For example,
you could alternate labels above and below with code like this:
> x <- 1:10
> y <- rep(0, 10)
> plot(x,y)
> text(x, y, rep("label", 10), pos=rep(c(1,3), 5))
because the pos parameter can be specified separately for each observation.
Duncan Murdoch
Thank you, Filippo Biscarini PS: These are the lines of codes that I have been using to generate the plot. plot( prova$x, prova$y, type="b", mar=c(0.5,0.5,0.5,0.5), xlab="basepairs", ylab="" ); text( prova$x, prova$y, prova$lab, pos=3, offset=2, cex=0.5 );
Duncan Murdoch wrote:
On 12/3/2007 12:21 PM, Biscarini, Filippo wrote:
Good evening, I am trying to add labels to the point of a simple plot, using the text() function; the problem is that sometimes, if two points are too close to each other, labels overlap and are no longer readable. I was wondering whether there are options that I can use to prevent this overlapping (by, for example, placing labels alternatively above and below the plotted curve), or whether I should use another set of graphical functions (grid or lattice packages). Does anybody have suggestions?
I don't think there are any functions to automatically avoid overlaps, but it is not hard to manually move some of the labels.
The OP might like to take a look at the orditorp function in package vegan, which is designed to add information from complex ecological data sets with many species to ordinations. It works out if a label can be placed and if not draws a point. The OP would have to modify it to try another place to plot, but that might be a basis from which to work. Of course, if this is a one-off project Duncan's solution is more than adequate. G For example,
you could alternate labels above and below with code like this:
> x <- 1:10
> y <- rep(0, 10)
> plot(x,y)
> text(x, y, rep("label", 10), pos=rep(c(1,3), 5))
because the pos parameter can be specified separately for each observation. Duncan Murdoch
Thank you, Filippo Biscarini PS: These are the lines of codes that I have been using to generate the plot. plot( prova$x, prova$y, type="b", mar=c(0.5,0.5,0.5,0.5), xlab="basepairs", ylab="" ); text( prova$x, prova$y, prova$lab, pos=3, offset=2, cex=0.5 );
______________________________________________ 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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Biscarini, Filippo wrote:
Good evening, I am trying to add labels to the point of a simple plot, using the text() function; the problem is that sometimes, if two points are too close to each other, labels overlap and are no longer readable. I was wondering whether there are options that I can use to prevent this overlapping (by, for example, placing labels alternatively above and below the plotted curve), or whether I should use another set of graphical functions (grid or lattice packages). Does anybody have suggestions?
Hi Filippo, Have a look at thigmophobe.labels in the plotrix package. Jim