Changing color of chart background based on value

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

Changing color of chart background based on value

Hassan Taweel
Hi All,

Is there a way to change the colour of the background on a line or a scatter graph based on values on the y axes? 
Say I am making a line chart, with date as the x variable and fat level as the y variable, and I wish to have the colour of the background in the graph to be green when the value of y is between 4 and 4.8, and orange when the value of y is between 3.3 and 4, and red when the value of y is < 3.3. Is there a way to do this?
Same in a scatter plot/chart?

Appreciate the help.
Regards
H.Z.

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Jon Peck
I don't think this is possible.  An alternative would be to add reference lines at the upper and lower boundaries.

On Sun, Oct 4, 2020 at 1:31 PM Hassan Taweel <[hidden email]> wrote:
Hi All,

Is there a way to change the colour of the background on a line or a scatter graph based on values on the y axes? 
Say I am making a line chart, with date as the x variable and fat level as the y variable, and I wish to have the colour of the background in the graph to be green when the value of y is between 4 and 4.8, and orange when the value of y is between 3.3 and 4, and red when the value of y is < 3.3. Is there a way to do this?
Same in a scatter plot/chart?

Appreciate the help.
Regards
H.Z.

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Bruce Weaver
Administrator
Can one generate a heat map plot to get the desired shaded areas and then
overlay a scatter-plot?  That approach worked in Stata (where contour = heat
map):

clear *
sysuse auto
* Overlay a scatter-plot on a heat map plot
twoway contour mpg mpg weight, ccuts(20 30) || ///
scatter mpg weight, msymbol(Oh) mcolor(black)

Stata_heatmap_scatterplot_overlay.png
<http://spssx-discussion.1045642.n5.nabble.com/file/t7186/Stata_heatmap_scatterplot_overlay.png>  


Andy W has a page on making heat maps with SPSS, which may be helpful:

  https://andrewpwheeler.com/2017/01/11/heatmaps-in-spss/

I don't know if one can easily overlay a scatter-plot.

HTH.


Jon Peck wrote
> I don't think this is possible.  An alternative would be to add reference
> lines at the upper and lower boundaries.
>
> On Sun, Oct 4, 2020 at 1:31 PM Hassan Taweel &lt;

> hassantaweel@

> &gt;
> wrote:
>
>> Hi All,
>>
>> Is there a way to change the colour of the background on a line or a
>> scatter graph based on values on the y axes?
>> Say I am making a line chart, with date as the x variable and fat level
>> as
>> the y variable, and I wish to have the colour of the background in the
>> graph to be green when the value of y is between 4 and 4.8, and orange
>> when
>> the value of y is between 3.3 and 4, and red when the value of y is <
>> 3.3.
>> Is there a way to do this?
>> Same in a scatter plot/chart?
>>
>> Appreciate the help.
>> Regards
>> H.Z.
>>
>> ===================== To manage your subscription to SPSSX-L, send a
>> message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text
>> except the command. To leave the list, send the command SIGNOFF SPSSX-L
>> For
>> a list of commands to manage subscriptions, send the command INFO REFCARD
>
>
>
> --
> Jon K Peck

> jkpeck@

>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Andy W
One approach I have listed here,
https://andrewpwheeler.com/2013/04/03/some-notes-on-single-line-charts-in-spss/.

So that is piping it in manually. For a data based approach here is how I
would try to tackle it. If you have a bunch, you need a dataset that defines
the corner of the boxes (begin/end here is the X variable, bottom/top is Y),
then in this part map to a color and an id for each unique box:

ELEMENT: polygon(position(link.hull((begin + end)*(bottom + top))),
color.interior(??COLORVARIABLE??),
                  transparency.interior(transparency."0.5"),
split(??IDFOREACHBOX??))

Sorry cannot test it out to show, no more SPSS for me since not at a Uni
anymore.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Bruce Weaver
Administrator
Andy, given the nature of your website, I reckon you ought to be eligible for
an author's license.  

John Hall, are you still getting your SPSS that way?  If so, please direct
Andy to where he can get one too!  

Cheers,
Bruce



Andy W wrote
> --- snip ---
> Sorry cannot test it out to show, no more SPSS for me since not at a Uni
> anymore.
> --- snip ---





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Kirill Orlov
I fully uphold the notion: Andy's gimmicks and the site are great!


05.10.2020 17:26, Bruce Weaver пишет:
> Andy, given the nature of your website, I reckon you ought to be eligible for
> an author's license.
>
> John Hall, are you still getting your SPSS that way?  If so, please direct
> Andy to where he can get one too!
>
> Cheers,
> Bruce
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Art Kendall
In reply to this post by Bruce Weaver
It certainly would be in IBM/SPSS's interest/benefit to be sure that retired
long time contributors to this forum/list continue to help the SPSS
community.  Contributors to this list such as Andy, John, Jon, David, Bruce,
ViAnn, Kiril, Progman, Eugene, Marta, Ryan, Anthony, and others have been
extremely helpful to me and I am sure to many others.

It goes without saying that retirees have more experience than beginners.


Disclosure.  I already have a lifetime license for 8 seats with all the
modules so such a practice would not benefit me.



-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Andy W
In reply to this post by Bruce Weaver
Well, life is weird. Doing some work with folks at Georgia State Univ, and my
affiliated ID stuff went through just today. They let students/faculty have
a license for their personal machine at that uni, so just piped in the code
for my V26 and I am good for now anyway.

So here is a bit lengthy example of setting up the data to do what I think
the OP wants and mashing up the boxes with a time series line plot.

**********************************************************.
data list free / year VCR.
begin data
1985    1881.3
1986    1995.2
1987    2036.1
1988    2217.6
1989    2299.9
1990    2383.6
1991    2318.2
1992    2163.7
1993    2089.8
1994    1860.9
1995    1557.8
1996    1344.2
1997    1268.4
1998    1167.4
1999    1062.6
2000    945.2
2001    927.5
2002    789.6
2003    734.1
2004    687.4
2005    673.1
2006    637.9
2007    613.8
2008    580.3
2009    551.8
2010    593.1
end data.
DATASET NAME Crime.
formats year VCR (F4.0).

*Computing regimes based on Y axis value.
DO IF VCR < 1000.
  COMPUTE Regime = 1.
ELSE IF VCR < 2000.
  COMPUTE Regime = 2.
ELSE.
  COMPUTE Regime = 3.
END IF.
FORMATS Regime (F1.0).
EXECUTE.

DO IF $casenum = 1.
  COMPUTE RegimeID = 1.
ELSE IF Regime = LAG(Regime).
  COMPUTE RegimeID = LAG(RegimeID).
ELSE IF Regime <> LAG(Regime).
  COMPUTE RegimeID = LAG(RegimeID) + 1.
END IF.
FORMATS RegimeID (F3.0).
EXECUTE.

DATASET DECLARE Boxes.
AGGREGATE OUTFILE='Boxes'
  /BREAK RegimeID
  /Regime = FIRST(Regime)
  /begin = MIN(year)
  /end = MAX(year).

DATASET ACTIVATE Boxes.
COMPUTE begin = begin - 0.5.
COMPUTE end = end + 0.5.
COMPUTE bottom = -1.
COMPUTE top = 3000.
FORMATS bottom top (F4.0).
*Due to formats does not show, but this works.
EXECUTE.

GGRAPH
  /GRAPHDATASET NAME="b" DATASET=boxes VARIABLES=begin end bottom top Regime
RegimeID
  /GRAPHDATASET NAME="v" DATASET=Crime VARIABLES=year VCR
  /GRAPHSPEC SOURCE=INLINE
  /FRAME INNER=YES.
BEGIN GPL
  SOURCE: b=userSource(id("b"))
  DATA: begin=col(source(b), name("begin"))
  DATA: end=col(source(b), name("end"))
  DATA: bottom=col(source(b), name("bottom"))
  DATA: top=col(source(b), name("top"))
  DATA: Regime=col(source(b), name("Regime"), unit.category())
  DATA: RegimeID=col(source(b), name("RegimeID"), unit.category())
  SOURCE: v=userSource(id("v"))  
  DATA: year=col(source(v), name("year"))
  DATA: VCR=col(source(v), name("VCR"))
  SCALE: linear(dim(1), min(1985), max(2010))
  SCALE: linear(dim(2), min(500), max(2500))
  GUIDE: legend(aesthetic(aesthetic.color.interior), null())
  GUIDE: axis(dim(1), label("Year"))
  GUIDE: axis(dim(2), label("Violent Crime Rate per 100,000"))
  ELEMENT: polygon(position(link.hull((begin + end)*(bottom + top))),
                                 color.interior(Regime), split(RegimeID),
                                 transparency.interior(transparency."0.5"),
                                 transparency.exterior(transparency."1"))
  ELEMENT: line(position(year*VCR), color.interior(color.black),
size(size."1"))
  ELEMENT: point(position(year*VCR), color.interior(color.black),
color.exterior(color.white), size(size."8px"))
END GPL.
**********************************************************.

<http://spssx-discussion.1045642.n5.nabble.com/file/t329824/Background.png>



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Changing color of chart background based on value

Art Kendall
In reply to this post by Art Kendall
It was simply a brain lapse that I omitted Rich.
He has often provided valuable insight.



-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants