[R] Shading the plot

David Winsemius dwinsemius at comcast.net
Sun Dec 4 03:26:17 CET 2011


On Dec 3, 2011, at 5:28 PM, avinash barnwal wrote:

> Hi Weylandt,
>
>
> I tried it but i was not successful.
>
> Here is the full code
>
> Any help would be great.
> ########################################################################
> time<-c("02-Jan-05","09-Jan-05","16-Jan-05","23-Jan-05","30- 
> Jan-05","06-Feb-05","13-Feb-05","20-Feb-05","27-Feb-05","06- 
> Mar-05","13-Mar-05",
> "20-Mar-05","27-Mar-05","03-Apr-05","10-Apr-05","17-Apr-05","24- 
> Apr-05","01-May-05","08-May-05","15-May-05")
> time<-as.Date(time,"%d-%b-%y")
> a2<- 
> c 
> ("81.96392786 
> ","81.96392786 
> ","82.16432866 
> ","82.56513026","82.76553106","79.96593186","78.16633267",
> "75.56713427 
> ","74.76753507 
> ","72.96793587 
> ","70.96793587","45.96793587","83.96793587","84.36873747",
> "84.56913828 
> ","84.56913828 
> ","84.56913828","84.56913828","84.36873747","84.36873747")
> a3<- 
> c 
> ("81.96392786 
> ","81.96392786 
> ","81.96392786","70.96392786","68.16432866","66.16432866",
> "62.16432866 
> ","58.56513026 
> ","56.56513026 
> ","54.56513026","48.56513026","49.76553106","52.76553106",
> "54.76553106 
> ","57.96593186 
> ","59.36673347","83.36673347","83.36673347","83.36673347",
> "83.56713427")
> j<-0
> for(i in 1:length(a3))
> {
> if(a2[i]>a3[i])
> {
> j<-j+1
> x[j]<-a2[i]
> y[j]<-a3[i]
> temp_time[j]<-time[i]
> }
> }
> plot(time,a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE)
> lines(time,a3,col='blue',ylab='',xlab=" ")
> polygon(c(temp_time,rev(temp_time)),c(x,y),col="grey")
> #########################################################################

What are the rules that govern requesting outside help in homework at  
your institution?

Your current code does not recognize  that there is line crossing. Nor  
do you describe what you mean by shading. If you wanted a rectangle  
within the lpot area it would drive one strategy and if you wanted  
only the area between the curves to be shaded it would drive a  
different strategy.

AND you never define "x" or "y".

-- 
David.



> On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt <
> michael.weylandt at gmail.com> wrote:
>
>> ? polygon
>> example(polygon)
>>
>> Michael
>>
>> On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal
>> <avinashbarnwal123 at gmail.com> wrote:
>>> Hi all,
>>>
>>> I have been trying to shade the specific part of the plot
>>>
>>> Part to be shaded
>>>
>>> 1. Any color whenever a2>a3
>>>
>>> 2. Any other color( Not same as 1) whenever a2<a3
>>>
>>> Suggest me some code for this task
>>>
>>> PLOT CODE for reference
>>>
>>>
>> ######################################################################################################
>>>
>> a2<- 
>> c 
>> ("81.96392786 
>> ","81.96392786 
>> ","82.16432866 
>> ","82.56513026","82.76553106","79.96593186","78.16633267",
>>>
>> "75.56713427 
>> ","74.76753507 
>> ","72.96793587 
>> ","70.96793587","45.96793587","83.96793587","84.36873747",
>>>
>> "84.56913828 
>> ","84.56913828 
>> ","84.56913828","84.56913828","84.36873747","84.36873747")
>>>
>> a3<- 
>> c 
>> ("81.96392786 
>> ","81.96392786 
>> ","81.96392786","70.96392786","68.16432866","66.16432866",
>>>
>> "62.16432866 
>> ","58.56513026 
>> ","56.56513026 
>> ","54.56513026","48.56513026","49.76553106","52.76553106",
>>>
>> "54.76553106 
>> ","57.96593186 
>> ","59.36673347","83.36673347","83.36673347","83.36673347",
>>> "83.56713427")
>>> plot(a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE)
>>> lines(a3,col='blue',ylab='',xlab=" ")
>>>
>> ######################################################################################################
>>>
>>> Thank you in the advance
>>> --
>>> Avinash Barnwal
>>> Final year undergraduate student
>>> Statistics and informatics
>>> Department of Mathematics
>>> IIT Kharagpur
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>
>
>
> -- 
> Avinash Barnwal
> Final year undergraduate student
> Statistics and informatics
> Department of Mathematics
> IIT Kharagpur
>
> 	[[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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list