[R] lattice library: xyplot and polygons
Renaud Lancelot
renaud.lancelot at cirad.fr
Sun Mar 10 19:03:35 CET 2002
Thanks Deepayan, it works fine. Below are the data and code for those
who might want to try.
Best regards,
Renaud
> Water
id label longitude latitude
515 21 Zone inondable -14.91929 15.27983
516 21 Zone inondable -14.91803 15.27967
517 21 Zone inondable -14.91765 15.27990
518 21 Zone inondable -14.91722 15.28029
519 21 Zone inondable -14.91706 15.28061
520 21 Zone inondable -14.91672 15.28125
521 21 Zone inondable -14.91566 15.28194
522 21 Zone inondable -14.91470 15.28189
523 21 Zone inondable -14.91334 15.28132
524 21 Zone inondable -14.91297 15.28057
525 21 Zone inondable -14.91362 15.27972
526 21 Zone inondable -14.91501 15.27931
527 21 Zone inondable -14.91573 15.27942
528 21 Zone inondable -14.91609 15.27896
529 21 Zone inondable -14.91655 15.27799
530 21 Zone inondable -14.91732 15.27777
531 21 Zone inondable -14.91802 15.27758
532 21 Zone inondable -14.91855 15.27808
533 21 Zone inondable -14.91914 15.27884
534 21 Zone inondable -14.91929 15.27983
604 25 Zone inondable -14.89753 15.23055
605 25 Zone inondable -14.89731 15.22856
606 25 Zone inondable -14.89784 15.22840
607 25 Zone inondable -14.89935 15.22814
608 25 Zone inondable -14.90030 15.22756
609 25 Zone inondable -14.90119 15.22746
610 25 Zone inondable -14.90149 15.22777
611 25 Zone inondable -14.90146 15.22835
612 25 Zone inondable -14.90228 15.22875
613 25 Zone inondable -14.90293 15.22937
614 25 Zone inondable -14.90332 15.23041
615 25 Zone inondable -14.90298 15.23109
616 25 Zone inondable -14.90201 15.23152
617 25 Zone inondable -14.90113 15.23206
618 25 Zone inondable -14.90051 15.23233
619 25 Zone inondable -14.90024 15.23305
620 25 Zone inondable -14.89996 15.23318
621 25 Zone inondable -14.89902 15.23299
622 25 Zone inondable -14.89894 15.23189
623 25 Zone inondable -14.89890 15.23123
624 25 Zone inondable -14.89800 15.23064
625 25 Zone inondable -14.89753 15.23055
1098 34 Zone inondable -14.87331 15.14367
1099 34 Zone inondable -14.87443 15.14398
1100 34 Zone inondable -14.87485 15.14436
1101 34 Zone inondable -14.87541 15.14516
1102 34 Zone inondable -14.87576 15.14656
1103 34 Zone inondable -14.87548 15.14816
1104 34 Zone inondable -14.87483 15.14857
1105 34 Zone inondable -14.87375 15.14881
1106 34 Zone inondable -14.87230 15.14951
1107 34 Zone inondable -14.87142 15.15006
1108 34 Zone inondable -14.87069 15.15028
1109 34 Zone inondable -14.86981 15.14998
1110 34 Zone inondable -14.86803 15.14950
1111 34 Zone inondable -14.86779 15.14766
1112 34 Zone inondable -14.86815 15.14673
1113 34 Zone inondable -14.86889 15.14658
1114 34 Zone inondable -14.86954 15.14628
1115 34 Zone inondable -14.87018 15.14572
1116 34 Zone inondable -14.87097 15.14583
1117 34 Zone inondable -14.87279 15.14584
1118 34 Zone inondable -14.87289 15.14478
1119 34 Zone inondable -14.87331 15.14367
>
> Asp <- diff(range(Water$longitude)) / diff(range(Water$latitude))
>
> xyplot(longitude ~ latitude,
+ data = Water, aspect = Asp,
+ panel = function(x, y){
+ for(i in unique(Water$id)){
+ cond <- Water$id == i
+ grid.polygon(x = Water$latitude[cond],
+ y = Water$longitude[cond],
+ gp = gpar(col = "black", fill = "light blue"),
+ default.units = "native")
+ }
+ })
>
Deepayan Sarkar wrote:
>
> I haven't checked it out, but I'm pretty sure grid.polygon will work
> if you add a default.units = "native" argument to it. Please let me know
> if it doesn't, I'll take a closer look.
>
> polygon will not work. I'll try to add a lpolygon along the lines of llines,
> lpoints etc for the next release.
>
> Deepayan
>
> --- Renaud Lancelot <renaud.lancelot at cirad.fr> wrote:
> > Dear R-Helpers,
> >
> > Is there a way to draw shaded (filled) polygons in panel graphs produced
> > by xyplot ? I made different trials (see below) with polygon() and
> > grid.polygon() but polygons are not drawn (probably for the same reason
> > that prevents the use of lines, points, etc. in xyplot panels).
> >
> > Thanks in advance,
> >
> > Renaud
> >
> > > Asp <- diff(range(Water$longitude)) / diff(range(Water$latitude))
> > > ### works but polygons are empty
> > > xyplot(longitude ~ latitude,
> > + data = Water, groups = id, aspect = Asp,
> > + panel = function(x, y, ...){
> > + panel.superpose(x, y, type = "l", col = 1,...)
> > + })
> > > ### does not work
> > > xyplot(longitude ~ latitude,
> > + data = Water, aspect = Asp,
> > + panel = function(x, y){
> > + for(i in unique(Water$id)){
> > + cond <- Water$id == i
> > + polygon(x = Water$latitude[cond], y = Water$longitude[cond],
> > + border = "black", col = "light blue")
> > + }
> > + })
> > > ### does not work
> > > xyplot(longitude ~ latitude,
> > + data = Water, aspect = Asp,
> > + panel = function(x, y){
> > + for(i in unique(Water$id)){
> > + cond <- Water$id == i
> > + grid.polygon(x = Water$latitude[cond],
> > + y = Water$longitude[cond],
> > + gp = gpar(col = "black", fill = "light blue"))
> > + }
> > + })
> > >
> >
> > --
> > Dr Renaud Lancelot, vétérinaire
> > CIRAD, Département Elevage et Médecine Vétérinaire (CIRAD-Emvt)
> > Programme Productions Animales
> > http://www.cirad.fr/presentation/programmes/prod-ani.shtml
> >
> > ISRA-LNERV tel (221) 832 49 02
> > BP 2057 Dakar-Hann fax (221) 821 18 79 (CIRAD)
> > Senegal e-mail renaud.lancelot at cirad.fr
> >
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
> __________________________________________________
> Do You Yahoo!?
> http://mail.yahoo.com/
--
Dr Renaud Lancelot, vétérinaire
CIRAD, Département Elevage et Médecine Vétérinaire (CIRAD-Emvt)
Programme Productions Animales
http://www.cirad.fr/presentation/programmes/prod-ani.shtml
ISRA-LNERV tel (221) 832 49 02
BP 2057 Dakar-Hann fax (221) 821 18 79 (CIRAD)
Senegal e-mail renaud.lancelot at cirad.fr
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list