How to add background color of a 2D chart by quadrant

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add background color of a 2D chart by quadrant

tom soyer
Hi,

I have a 2D chart that is divided into four quadrants, I, II, III, IV:

plot(1:10,ylim=c(0,10),xlim=c(0,10),type="n")
abline(v=5,h=5)
text(x=c(7.5,7.5,2.5,2.5),y=c(2.5,7.5,7.5,2.5),labels=c("I","II","III","IV"))
I would like to fill each quadrant with a background color unique to the
quadrant. Does anyone know how to do this in R?

Thanks,

--
Tom

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add background color of a 2D chart by quadrant

Greg Snow-2
The basic approach is:

1. call plot (sets up the main plotting)
2. call rect for each quadrant (or polygon if you prefer)
3. add the points with the points function (replotting any points
covered by the rectangles)
4. add any additional notation (calling functions such as text, axis,
etc.).

If you need the coordinates to use for your corners in step 2, look at
?par and scroll to the section on 'usr', or look at ?grconvertX in R2.7,
or the cnvrt.coords function in the TeachingDemos package.

If that does not do what you want, give us some more detail on what you
are trying to accomplish.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of tom soyer
> Sent: Monday, April 07, 2008 2:02 PM
> To: [hidden email]
> Subject: [R] How to add background color of a 2D chart by quadrant
>
> Hi,
>
> I have a 2D chart that is divided into four quadrants, I, II, III, IV:
>
> plot(1:10,ylim=c(0,10),xlim=c(0,10),type="n")
> abline(v=5,h=5)
> text(x=c(7.5,7.5,2.5,2.5),y=c(2.5,7.5,7.5,2.5),labels=c("I","I
> I","III","IV"))
> I would like to fill each quadrant with a background color
> unique to the quadrant. Does anyone know how to do this in R?
>
> Thanks,
>
> --
> Tom
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add background color of a 2D chart by quadrant

Mike Prager
In reply to this post by tom soyer
"tom soyer" <[hidden email]> wrote:

> I have a 2D chart that is divided into four quadrants, I, II, III, IV:
>
> plot(1:10,ylim=c(0,10),xlim=c(0,10),type="n")
> abline(v=5,h=5)
> text(x=c(7.5,7.5,2.5,2.5),y=c(2.5,7.5,7.5,2.5),labels=c("I","II","III","IV"))
> I would like to fill each quadrant with a background color unique to the
> quadrant. Does anyone know how to do this in R?

In response to a similar question no more than two weeks ago, I
posted detailed code as an example.  I expect it would be easy
to modify my example to fit your question.  

If you search the group archives, you should be able to find it.
The thread title was "background color in scatterplots".

MHP

--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
[hidden email] 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.