turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- Consistent Colors on a Graph when replicating it s...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-27-2016 03:23 PM

Using Proc GPLOT I have a line graph showing number of prescriptions by drug type over several years. Each graph is recreated for each state.

However, I can't seem to get the colors to remain consistent for each drug when I replicate the graph for each state.

Is there anyway to indicate if the drug='Ibuprofen' then the line color should be green, etc. I can't seem to find an option to do that.

Here's the code I used:

```
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
SYMBOL1
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2
CV = _STYLE_
;
SYMBOL2
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2
CV = _STYLE_
;
SYMBOL3
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2
CV = _STYLE_
;
Legend1
FRAME
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE
;
Axis2
STYLE=1
WIDTH=1
MINOR=NONE
;
PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT statecd, hcv_rc ,Year_qtr ,
SUM(num_presc) AS num_presc_SUM
FROM HCV.HCVX
GROUP BY statecd, hcv_rc,Year_qtr
ORDER BY statecd, hcv_rc,Year_qtr;
QUIT;
PROC GPLOT DATA = WORK.SORTTempTableSorted;
PLOT num_presc_SUM * Year_qtr =hcv_rc
/
VAXIS=AXIS1
HAXIS=AXIS2
FRAME SKIPMISS
LEGEND=LEGEND1
;
by statecd;
RUN; QUIT;
```

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to einstein

05-27-2016 03:43 PM

The best way to do this is to use PROC SGPLOT with an attributes map. If you look at pages 8-9 of my paper (see the link below), you will see an example this. For your case, your code will look something like this:

```
data attrmap;
retain id "myid";
length linestyleelement $ 10 markerstyleelement $ 10;
input value $ linestyleelement $ markerstyleelement $;
cards;
drug1 GraphData1 GraphData1
drug2 GraphData2 GraphData2
drug3 GraphData3 GraphData3
;
run;
proc sgplot data=work.SORTEDTempTableSorted dattrmap=attrmap;
series x=year_qtr y=num_presc_sum / group=hcv_rc attrid=myid;
run;
```

Hope this helps!

Dan

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

06-03-2016 01:00 PM

Thanks! This was actually quite helpful!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to einstein

05-27-2016 04:16 PM

Some times it helps to make sure that all values of your grouping variables such as hvc_rc appear within others (your statecd) even if the Y value is missing.

The attributes is preferred but if you stick with GPLOT or have an older version of SAS such as 9.2 then the added value will help, especially when sorted.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to einstein

05-27-2016 07:15 PM

Here ar two more resources with examples:

Specify the colors of groups in SAS statistical graphics

A simple trick to include (and order!) all categories in SGPLOT legends

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

06-03-2016 01:01 PM

Thanks Rick! This was also super helpful!