Re: [R] Conditional ploting with logical vector

From: ken knoblauch <>
Date: Sat, 05 Apr 2008 10:38:36 +0000 (UTC)

Armin Goralczyk <agoralczyk <at>> writes:
> In a function I have a plot and want to add symbols/text only when
> indicated by a logical vector (which was generated by the function
> before, not manually like in the following example):
> plot(1:10, 1:10)
> lv <- c(T,T,T,F,F,F,T,T,T,F)
> text(1:10, 1:10, '*', pos = 3)
> In this example the asterisk is plotted at every yx-coordinate
> indicated. How Can I make it appear only when 'TRUE' in the lv?
Maybe, someone has a more elegant solution, but this works,

plot(1:10, 1:10)
lv <- c(T,T,T,F,F,F,T,T,T,F)
lv2 <- ifelse(lv, TRUE, NA)
text(1:10, (1:10) * lv2, '*', pos = 3)

HTH ken mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 05 Apr 2008 - 10:44:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Apr 2008 - 13:30:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive