Skip to content

Polygon shaded area

10 messages · Uwe Ligges, Eik Vettorazzi, John Kane +2 more

#
Hi all,

I have two vectors (columns) called "efinal" and "efinal 2".

I want to plot them on the same plot and "draw" a shaded area beween the
two lines using function polygon

I have tried all but I don ?t understand the polygon area, can you help me
with examples?

plot(efinal,type="l",ylim=range(min(efinal2),
max(efinal)),ylab="",main="plot")

par(new=T)
plot(efinal2,type="l",ylim=range(min(efinal2), max(efinal)),ylab="")

The efinal are two temporal series I attach?
#
On 02.08.2012 14:33, Jose Narillos de Santos wrote:
Don't know, at least not attached to the message through R-help.

I don't see what the problem is to construct a polygon()
Just insert x and y values of both series in an appropriate order and 
connect them at the end.

If you fail, provide fully reproducible code (we do not have efinal nor 
efinal 2 for now).

Best,
Uwe Ligges
#
Hi Jose,
how about this

example(polygon)

I think the second one is pretty much what you want.

cheers.

Am 02.08.2012 14:33, schrieb Jose Narillos de Santos:

  
    
#
Hi I attach my function. No error message (it seems a line appears but
nothing similar to examples(polygon))



2012/8/2 Eik Vettorazzi <E.Vettorazzi at uke.de>
#
Not attached.  R-help typically strips out any attachment to prevent malware being spread.  

The best way to supply sample date is to use the dput() command.  See ?dput for details but basically just say dput(myfile) and copy the results into your email.  Readers can directly paste the file into their R console and see exactly what your data is.

John Kane
Kingston ON Canada

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
#
Data came through fine.
   I  can  never  plot a polygon without help but I think you have a data
   problem.
   Try this:
   efinal == efinal2



   John Kane
   Kingston ON Canada

   -----Original Message-----
   From: narillosdesantos at gmail.com
   Sent: Thu, 2 Aug 2012 16:55:23 +0200
   To: jrkrideau at inbox.com
   Subject: Re: [R] Polygon shaded area

Hi many thanks,
That is my data.
c(0.9525, 0.89785, 0.8931, 0.9308, 0.89335, 0.8729, 0.8521, 0.8556, 
0.88135, 0.9093, 0.89375, 0.91155, 0.8881, 0.86655, 0.8927, 0.8898, 
0.8703, 0.84863, 0.81745, 0.8349, 0.8248, 0.85995, 0.8686, 0.83765, 
0.86075, 0.8609, 0.8528, 0.8837, 0.8917, 0.8671, 0.87205, 0.90255, 
0.87485, 0.8856, 0.86665, 0.8731, 0.8558, 0.8353, 0.8557130916294, 
0.861971323468187, 0.865900731747475, 0.868624652247, 0.870578199623624, 
0.871984527163596, 0.872976198154798, 0.873639584912775, 0.8740346818528, 
0.87420517054346, 0.874184027040643, 0.873996870459551)
c(0.9525, 0.89785, 0.8931, 0.9308, 0.89335, 0.8729, 0.8521, 0.8556, 
0.88135, 0.9093, 0.89375, 0.91155, 0.8881, 0.86655, 0.8927, 0.8898, 
0.8703, 0.84863, 0.81745, 0.8349, 0.8248, 0.85995, 0.8686, 0.83765, 
0.86075, 0.8609, 0.8528, 0.8837, 0.8917, 0.8671, 0.87205, 0.90255, 
0.87485, 0.8856, 0.86665, 0.8731, 0.8558, 0.8353, 0.8073853773588, 
0.793625614508213, 0.782194675217125, 0.771969223705801, 0.762514145317377, 
0.753606286765605, 0.745113084762604, 0.736948166992827, 0.729051539041001, 
0.721379519338542, 0.713899131829559, 0.706584757398851)

   2012/8/2 John Kane <[1]jrkrideau at inbox.com>

   > The efinal are two temporal series I attach?

     Not attached.  R-help typically strips out any attachment to prevent
     malware being spread.
     The best way to supply sample date is to use the dput() command.  See
     ?dput for details but basically just say dput(myfile) and copy the results
     into your email.  Readers can directly paste the file into their R console
     and see exactly what your data is.
     John Kane
     Kingston ON Canada
     ____________________________________________________________
     FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
     family!
     Visit [2]http://www.inbox.com/photosharing to find out more!
     _________________________________________________________________

   [3]3D Marine Aquarium Screensaver Preview 
   Free 3D Marine Aquarium Screensaver
   Watch  dolphins,  sharks  &  orcas  on  your  desktop! Check it out at
   [4]www.inbox.com/marineaquarium

References

   1. mailto:jrkrideau at inbox.com
   2. http://www.inbox.com/photosharing
   3. http://www.inbox.com/marineaquarium
   4. http://www.inbox.com/marineaquarium
#
Hi Jose,
this should work (but I think you need a deeper understanding, what
plot(efinal) does, see ?plot):

plot(efinal,ylim=range(c(efinal,efinal2)),type="n",ylab="")
xv<-seq_along(efinal)
polygon(c(xv,rev(xv)),c(efinal,rev(efinal2)),col="red")

cheers

Am 02.08.2012 16:36, schrieb Jose Narillos de Santos:

  
    
#
On Thu, Aug 2, 2012 at 5:53 PM, Jose Narillos de Santos
<narillosdesantos at gmail.com> wrote:
c() is for combining vectors [think "concatenate"] and the reason you
have to combine xy with xy-reversed is to draw both sides of the
polygon: imagine I asked you to draw a square without raising your
pencil. However you do it, you'll go opposite directions along the top
and the bottom. Same idea leads to the rev() inside polygon.
Maybe this helps:

tframe <- data.frame(dat =  1:10,  day = Sys.Date() + 1:10)
# t is a bad variable name because there's a t = transpose function
which is really important

plot(dat ~ day, data = tframe)

with(tframe, polygon(c(day, rev(day)) + 0, c(dat, rep(0, length.out =
length(dat))), col = "blue"))

Best,
Michael