[R] Conditional ploting with logical vector

ken knoblauch ken.knoblauch at inserm.fr
Sat Apr 5 12:38:36 CEST 2008

Armin Goralczyk <agoralczyk <at> gmail.com> 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

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)



More information about the R-help mailing list