BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jteres
Obsidian | Level 7

plotHi-

Let me explain the larger goal. I want to view a series plot, and I want to overlay multiple block plots to allow for overlapping periods of time. For this example, let's say I want to look at MS Stock price, and I want to see it in the context of the Mac OS 9 release lifespan and the Windows 2000 lifespan. So each of those software release/availability periods will be represented by a block plot, and the stock is a series plot.

First, here's my data code:

data MSevents ;
     input Date1 date9. MRelease $5. ;
     format Date1 mmddyy10. ;         
     label MRelease = "Windows Release" ;
     datalines ;
01mar2000 2000
01nov2001
;
run ;       

data AppleEvents ;
     input Date2 date9. ARelease $5. ;
     format Date2 mmddyy10. ;
     label ARelease = "Apple Release" ;
     datalines ;
01nov1999 OS 9
02apr2001
;
run ;

proc sort data = sashelp.stocks (keep = date stock close)
     out = MSstock ;
     where stock = "Microsoft" ; 
     by date ;
run ;

data MSplotdata ;
     set MSStock MSEvents AppleEvents ;
run ;

Next, here's my template code:

proc template ;
     Define StatGraph MSBlockSeries ;
          BeginGraph ;
               Layout Overlay /    xAxisOpts      = (  TimeOpts = (   Interval            = Quarter
                                                                      TickValueFormat     = mmddyy10.
                                                                      TickValueFitPolicy  = RotateThin))

                                   /*x2axisopts     = (  timeopts = (   display   = none)*/ ;

                    BlockPlot      x         = date1        
                                   block     = MRelease     /    xAxis = x2 
                                                                 DataTransparency    = .75    
                                                                 Display             = (fill)
                                                                 FillType            = alternate
                                                                 FillAttrs           = (color = white)
                                                                 AltFillAttrs        = (color = blue)
                                                                 ExtendBlockOnMissing= false  ;
                                                                                               
                    BlockPlot      x         = date2       
                                   block     = ARelease     /    xAxis = x2
                                                                 DataTransparency    = .75    
                                                                 Display             = (fill)
                                                                 FillType            = alternate
                                                                 FillAttrs           = (color = white)
                                                                 AltFillAttrs        = (color = red)
                                                                 ExtendBlockOnMissing= false ;
                                                                                           
                    SeriesPlot     x    = date
                                   y    = close / lineattrs = (color = black pattern = solid) ;                                       
               EndLayout ;
          EndGraph ;
     End ;
run ;

Now, as for explanation, I am using the alternate block plot based on Prashant's paper "Off the Beaten Path" from SGF 2012, specifically the segmented Time Series Plot on page 13.

What I noticed, though, was that having a color alternate with "white" means that the white surrounding one block will mute the effect of the color beneath it. See the attached PDF for the full code (including an alternate version of the template code where I switch the order of the blocks).

Ideally, what I would like is to have a colored block surrounded by blanks rather than white so it doesn't affect the colors beneath it. Is that possible? Maybe I'm taking the wrong approach?

Thanks!

Jed

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Driving back from out-of-town, I remembered that any FILLATTRS can have its own independent transparency.  So, if you are using an overlay of two block plots, you can set the transparency for the FillAttrs to GD1 and GD2 with 50% transparency, and the AltFillAttrs with Transparency=1.   Here is the graph with two overlaid block plots where the white blocks are fully transparent.  The colored blocks are 50% transparent, so you can see where the overlap is.

Labels for one are at the top, and the other at the bottom.  To me, the OS releases for each company are clearly visible in the "Stacked" plot I sent earlier and it avoids the color blending as happens in this one.

Overlay_Trans.png

View solution in original post

7 REPLIES 7
DanH_sas
SAS Super FREQ

What if you wrapped your BLOCKPLOT statements inside of INNERMARGIN/ENDINNERMARGIN so that they are bands along the bottom of the plot. Would that be acceptable?

jteres
Obsidian | Level 7

Thanks for the response Dan, but no, that's not really what I'm looking for. In my real-life example, I have more blocks to overlap, and using the InnerMargin just moves them further away from the series plot.

I really want to have the series overlaid on the color blocks, similar to what Prashant did in his Time Series Segmentation graph in the Off the Beaten Path paper https://support.sas.com/resources/papers/proceedings12/267-2012.pdf.

Jay54
Meteorite | Level 14

The "Timeseries Segment Graph" included in Prashant's paper has various plot statements overlaid on a single block plot.  Actually, this is one of my graphs that Prashant included in his paper (along with a few oothers).   I have already sent you an example of how to overlay series plot on a block plot in the answer to your other question:  https://communities.sas.com/message/206175#206175.

Block plots fill the region,  So, overlaying them in the same container will have one hide the other.  You can certainly use transparency.  So, a block plot with white and pink segments can overlay one with yellow and blue segments (with 50% tansparency).  You will see segments from both plots, with various color combinations.  You have already done that in your example.  That is probably the best you can do with a Block plot other then separating them so each will fill only part (say half) of the height of the plot.

You could also use multiple BAND plots to create a similar effect, to acheive the fill / nofill regions you seem to want.  Have you tried that?  With SAS 9.4M1, you can use the POLYGON plot to draw the bands (rectangles) only where you want.

Can you attach an image of such a graph that you want to make, and what is the significant comparisons you want to make?  If we can understand your needs better, maybe we can suggest a way.

Jay54
Meteorite | Level 14

With some more experimentation, I could do this.  Is this closer to what you want?

Overlay_Half.png

jteres
Obsidian | Level 7

Hi Sanjay-

Thanks for weighing in. I appreciate your time.

For the benefit of others who might stumble across this thread, and to clarify what it is I'm trying to achieve, allow me to lay out the history of this question.

What I am trying to achieve is to have a series plot overlaid against colored bars representing periods of time. There is a very clear example of how to do this elsewhere; the example shows Microsoft stock prices over time against different Windows release availability periods as represented by colored bars. This is achived using BlockPlots in GTL.

The difference between this and what I'd like to do is that I want to allow for overlapping event durations. The example I've been using in this forum is showing MS stock price against Windows version eras as well as Apple Mac OS eras, but you could imagine other situations. Maybe you want to show systolic blood pressure readings over time, and want to capture different medications or doses as well as lifestyle changes, like an exercise regimen or diet.

The first attempt at doing this was to try to break up the plot area and show the two different event timelines in stacked colored blocks. This was a dead end for me, as Sanjay revealed that you can't overlay a series plot on a lattice plot. (that said, he posted a nice solution to that in this thread!).

The next attempt for me was to use multiple block plots, with each one assigned a single event and color code. By setting the transparency around .6, the overlapping periods would show up as different colors. In the PDF I attached to my original post, I show two versions of one example. There is a period of time, represented by light red, that corresponds to the release and subsequent availability of Windows 2000. There is another period of time, represented by light blue, that corresponds to the release and subsequent availability of Mac OS X. The overlapping window of time (no pun intended) is purplish, and depends on which BlockPlot is drawn first. Red over blue shows up a little differently than blue over red, but they both illustrate the same idea of overlap.

This was fine, and gave me the visualization of overlap I was looking for. However, as I was finalizing my code, I noticed that my transparency setttings didn't change anything. I realized that this is because the technique I was using to show individual blocks relies of alternating colors for different periods of time. Each different event window is represented by three points in time- the beginning of the timeline I'm plotting, the starting point for the event of interest, and the ending point for the event of interest (or the end of the graphing data, if that is sooner than that end of the event period or if it's unknown/unobserved). The way it's coded in my example, the periods of time before and after the event of interest (e.g., before windows 2000 came out and after windows xp came out) show up as white.

But when you overlay a white block on top of a colored block, it mutes the color (assuming the transparency is less than 0). That's creating problems for my visual, and that's the issue that I was trying to resolve.

So, in summary, I entertained the idea of showing stacked blocks, but abandoned that idea in favor of having overlapping blocks. I was able to create the graph I wanted, but have not been able to address the issue of getting washed out colors by overlaying white blocks on top of colored blocks. In the PDF attached to the original post, I show the exact graph I want. The issue is that, in the first one, the red bar is lighter than I'd like it to appear, and in the second one, the blue bar is lighter than I'd like it to appear. The middle looks fine, regardless of whether it's reddish purple or blueish purple.

I have not tried to address this using BandPlots; I will try that next. If that doesn't work, based on the information at hand, it sounds like using the POLYGON plot is the best solution to my specific problem.

I'll look into the BandPlot approach and check back to keep people up to speed. 9.4 is still a few months off for my team, so I hope this works!

Thanks again to Dan and Sanjay for offerering suggestions and solutions, and most importantly, for your time and interest. I'll let you know how I make out with Band plots. I hope my explanaiton helps clarify why I'm still trying to tackle this.

Thanks,

Jed

Jay54
Meteorite | Level 14

Driving back from out-of-town, I remembered that any FILLATTRS can have its own independent transparency.  So, if you are using an overlay of two block plots, you can set the transparency for the FillAttrs to GD1 and GD2 with 50% transparency, and the AltFillAttrs with Transparency=1.   Here is the graph with two overlaid block plots where the white blocks are fully transparent.  The colored blocks are 50% transparent, so you can see where the overlap is.

Labels for one are at the top, and the other at the bottom.  To me, the OS releases for each company are clearly visible in the "Stacked" plot I sent earlier and it avoids the color blending as happens in this one.

Overlay_Trans.png

jteres
Obsidian | Level 7

Perfect! The individual transparency levels is exactly the solution.

For my purposes, seeing the color bleeding for overlap is helpful, especially with more than 2 non-exclusive event dimensions. The real use case isn't looking at Microsoft stock, but I'm being a little conservative in terms of staying within compancy policy about sharing data etc. Probably too much so, but better safe than sorry in this case.

Thanks again, Sanjay! This is great.

Jed

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1759 views
  • 1 like
  • 3 in conversation