Hi Folks, I'd be grateful for good suggestions about the following. I'm plotting a family of (X,Y) curves (for different levels of another variable, Z): say 6 curves in all but could be more or less -- it's a rather variables situation. I'd like to label each curve with the value of Z that it corresponds to. The problem is that the layout (shapes, spacings, ranges of X over which non-NA values of Y get plotted) of the curves are very variable, and somewhat unpredictable beforehand. Of course one could simply wait until the graph was done, and then by hand position one's labels to the best effect. That, given time, is on a certain sense the optimum solution. But I'd like to be able to do a satisfactory job automatically, and quickly! This is the sort of problem already solved, in one particular way, in contour(). But here the curves are broken at the labels and the labels are centred on the curves (though nicely aligned with the curves). It might be satisfactory for me to place each label so that its baseline is on its curve, thus without overlaying the curve with the text. So maybe a "displaced" analogue of the way contour() does it (including alignment of the text) may be OK. Anothe possibility, for instance, is to draw lines from the ends of the curves to antries in a plotted table of Z-values. This could end up looking very untidym, though. I grant that this is a vague query. I'm still trying to form a clear view of how it ought to be approached; and I don't have R code to refer to and experiment with (that of contour() is hidden in its "method"). But people out there must have faced it, and I'd be grateful for their own feedback from the coal-face! With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-08 Time: 21:17:13 ------------------------------ XFMail ------------------------------
Dr. Harrell's Hmisc package has labcurve. --Matt -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ted Harding Sent: Wednesday, July 16, 2008 1:17 PM To: r-help at stat.math.ethz.ch Subject: [R] Labelling curves on graphs Hi Folks, I'd be grateful for good suggestions about the following. I'm plotting a family of (X,Y) curves (for different levels of another variable, Z): say 6 curves in all but could be more or less -- it's a rather variables situation. I'd like to label each curve with the value of Z that it corresponds to. The problem is that the layout (shapes, spacings, ranges of X over which non-NA values of Y get plotted) of the curves are very variable, and somewhat unpredictable beforehand. Of course one could simply wait until the graph was done, and then by hand position one's labels to the best effect. That, given time, is on a certain sense the optimum solution. But I'd like to be able to do a satisfactory job automatically, and quickly! This is the sort of problem already solved, in one particular way, in contour(). But here the curves are broken at the labels and the labels are centred on the curves (though nicely aligned with the curves). It might be satisfactory for me to place each label so that its baseline is on its curve, thus without overlaying the curve with the text. So maybe a "displaced" analogue of the way contour() does it (including alignment of the text) may be OK. Anothe possibility, for instance, is to draw lines from the ends of the curves to antries in a plotted table of Z-values. This could end up looking very untidym, though. I grant that this is a vague query. I'm still trying to form a clear view of how it ought to be approached; and I don't have R code to refer to and experiment with (that of contour() is hidden in its "method"). But people out there must have faced it, and I'd be grateful for their own feedback from the coal-face! With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-08 Time: 21:17:13 ------------------------------ XFMail ------------------------------ ______________________________________________ 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.
2008/7/16 Ted Harding <Ted.Harding@manchester.ac.uk>:> Hi Folks, > I'd be grateful for good suggestions about the following. > > I'm plotting a family of (X,Y) curves (for different levels > of another variable, Z): say 6 curves in all but could be > more or less -- it's a rather variables situation. > > I'd like to label each curve with the value of Z that it > corresponds to. > > But people out there must have faced it, and I'd be grateful > for their own feedback from the coal-face! >Isn't this why we have colour vision? Just use 6 different colours and a legend. Or use linestyles and colours. Trying to do neat labelling along general lines like contour does is going to fail in edge cases such as if two lines are very close together. Contour can be fairly sure the lines will have sensible spacing unless it's mapping cliffs. I looked at the underlying C code for contour a while back with a view to using the algorithms in another package, but I gave up pretty quickly. The generated contour lines and labels are quite beautiful, but the code gave me a headache. Barry [[alternative HTML version deleted]]