# [R-sig-teaching] Shading the solution of quadratic inequality

Randall Pruim rpruim at calvin.edu
Thu Feb 16 16:07:33 CET 2012

```I'm not sure exactly what sort of plot was desired, but I'll offer 1.5
possibilities.

Currently you can do something like this:

require(mosaic)
plotFun( x^2 - 4 ~ x , xlim=c(-6,6), col='blue' )
plotFun( (x^2 - 4)/as.numeric(x^2 -4 > 0) ~ x , xlim=c(-6,-2),
add=TRUE, col='blue', lwd=4 )

It is a bit of kludge since I'm using division by 0 to hide part of
the function.  You can adjust colors, line thickness, and alpha to
your particular sensitivities.  And you can use type='h' if you want a
"filled in version".

Soon, you should be able to do

plofFun( x^2 - 4 ~ x, groups=(x^2-4>0) )

If you find yourself wanting to plot "mathematical" functions like
this, I encourage you to give plotFun() a try and let us know how you
like it.

---rjp

On Feb 16, 2012, at 9:42 AM, R. Michael Weylandt wrote:

> You should probably say more about which graphics engine you are
> using, but here's a start:
>
> curve(x^2-4, from = -3, to = 3)
> x <- seq(-3, 3, length.out = 200)
> polygon(c(x, rev(x)), c(x^2-4, rep(Inf, length(x))), col = 2)
>
> The red is a little "oppressive" so I'd try to add transparency if
> your device supports it. Adding a shade above/below argument to curve
> based on the same principles might be a fun exercise too...
>
> Michael
>
> On Thu, Feb 16, 2012 at 9:13 AM, AbouEl-Makarim Aboueissa
> <aaboueissa at usm.maine.edu> wrote:
>> Dear all R Users:
>>
>> How can I shade the solution (-Inf,-2) or (2,Inf) of the inequality
>> -x^2+4<0 within the curve of f(x)=-x^2+4.
>>
>> and
>>
>> the solution (-Inf,-2)or(2,Inf) of the inequality x^2-4>0 within
>> the curve of
>> f(x)=x^2-4.
>>
>>
>> with many thanks
>>
>> abou
>>
>>
>> ==========================
>> AbouEl-Makarim Aboueissa, Ph.D.
>> Associate Professor of Statistics
>> Graduate Program Coordinator
>> Department of Mathematics & Statistics
>> University of Southern Maine
>> 96 Falmouth Street
>> P.O. Box 9300
>> Portland, ME 04104-9300
>> USA
>>
>>
>> Tel: (207) 228-8389
>> Fax: (207) 780-5607
>> Email: aaboueissa at usm.maine.edu
>>          aboueiss at yahoo.com
>>
>> Office: 301C Payson Smith
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-teaching at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

```