[R] fill the space between to lines
baptiste auguie
ba208 at exeter.ac.uk
Sun Mar 8 18:09:34 CET 2009
Hi,
Try:
> polygon(c(x1, rev(x2)), c(y1, rev(y2)), col="grey")
In general you might need to make sure the data is well ordered.
Hope this helps,
baptiste
On 8 Mar 2009, at 16:52, Martin Batholdy wrote:
> hi,
>
> the code below produces me two curved lines.
>
> Now I want to fill the space between these curves with a color and I
> don't have any idea how to do that with R.
>
>
> I tried it with the polygon() function but it didn't worked out.
>
>
>
> Can someone her give me a hint on that?
>
> thanks!
>
>
>
>
>
> x1 <- c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,
> 1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,
> 3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0)
> x2 <- c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,
> 1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,
> 3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0)
>
> y1 <- c(-0.04720997,0.04621043,0.13917323,0.23157407,0.32327960,
> 0.41411949,0.50387776,0.59228513,0.67901664,0.76370180,
> 0.84595616,0.92543926,1.00192864,1.07538026,1.14594154,
> 1.21390906,1.27965609,1.34356488,1.40598321,1.46720566,
> 1.52747146,1.58697039,1.64585138,1.70423095,1.76220039,
> 1.81983159,1.87718151,1.93429563,1.99121055,2.04795595,
> 2.10455610,2.16103096,2.21739711,2.27366841,2.32985649,
> 2.38597121,2.44202094,2.49801286,2.55395316,2.60984716,
> 2.66569949)
>
> y2 <- c(0.5071367,0.5653217,0.6239643,0.6831689,0.7430687,0.8038342,
> 0.8656814,0.9288794,0.9937533,1.0606735,1.1300245,1.2021468,
> 1.2772628,1.3554166,1.4364607,1.5200986,1.6059570,1.6936536,
> 1.7828406,1.8732236,1.9645632,2.0566696,2.1493940,2.2426199,
> 2.3362558,2.4302300,2.5244855,2.6189767,2.7136672,2.8085272,
> 2.9035325,2.9986630,3.0939022,3.1892363,3.2846536,3.3801443,
> 3.4757000,3.5713134,3.6669785,3.7626899,3.8584430)
>
> plot(c(),c(),ylim=c(0,4),xlim=c(0,4))
>
> lines(x1,y1,col="gray80",lwd=1.5)
> lines(x2,y2,col="gray80",lwd=1.5)
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list