[R] contour(): lines & labels in different colours?

David Winsemius dwinsemius at comcast.net
Sun Nov 22 23:21:25 CET 2009


On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote:

> Hi Ted,
>
> This won't solve your problem, but a small improvement might
> be to place the labels over the lines rather than the other
> way around. It will definitely avoid putting red lines over
> black ones:
>
> x <- -6:16
> z <- outer(x,x)
> contour(z, labels="", col=2)
> contour(z, lty=0, labcex=1, add=TRUE)

I played around a bit with you example, and can get almost the desired  
color and lack of cutting through labels. There is the possibility of  
plotting empty labels that create a space in the curves for the later  
labels-without-lines overlay:

x <- -6:16
z <- outer(x,x)
contour(z, labels="    ", col=2, labcex=1.5, drawlabels=TRUE)
contour(z, lty=0, labcex=1.5, add=TRUE)


>
> Cheers,
> Peter
>
>
> (Ted Harding) wrote:
>> Greetings, All!
>> I want to draw contour lines in red, using contour(), but also
>> have the contour labels (for the level-values) in black so that
>> they will stand out against a coloured background already generated
>> using filled.contour() (the background shades from green at low
>> levels of "risk" to red at high levels).
>> In any case, contour labels in red are already somewhat inconspicuous
>> with contour lines in red, regardless of background.
>> I see nothing in ?contour nor in ?par about this.
>> One way to approach it could be to first draw the labelled contours
>> in black, and then overlay by re-drawing (with out labels) in red.
>> This would sort-of work, but the red contour lines would then cut
>> through the black numbers, which is somewhat undesirable. Also
>> (I've tried it) you can get show-through along the contour lines
>> from the black layer, which is nasty.
>> Any suggestions?
>> With thanks,
>> Ted.
>> --------------------------------------------------------------------
>> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 22-Nov-09                                       Time: 17:06:08
>> ------------------------------ 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.
>>
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list