Message-ID: <CAFxDEqL0XJAyxzfG7zz2JDeo9GTFektNar8KCOCO1LhWHEt1ng@mail.gmail.com>
Date: 2014-02-28T15:10:41Z
From: mamuash bukana
Subject: Conditional polygon colouring
Dear R users
I want to paint parts of a polygon with different colours conditional
to values of the variable.
Example:
f<-seq(1,33)
g<-sin(f)
i<-rep(0,33)
ff<-c(f,rev(f))
gg<-c(g,rev(i))
plot(ff,gg,type="n")
polygon(ff,gg,col=2) # but I wanted to plot areas below and above the
x-axis with different colours.
In this attempt, I tried the following:
g2<-array(NA,33)
for(j in 1:33){
g2[j]<-ifelse(g[j]<=0,0,g[j])
}
gg2<-c(g2,i)
plot(ff,gg,type="n")
polygon(ff,gg,col=2)
lines(polygon(ff,gg2,col=4)) # but in this plot there are many
overlaps on the x-axis when 0 is substituted for negative g values.
May someone suggest me how to plot the two regions (above and below
x-axis) without affecting the actual plot region with different
colours please?