- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I copied here an answer from previous question see below. However, in this example 3 median for same treatment is plotted at same stop, how to make that Week 12 all 3 treatment would be plotted next to each other (same for week26) to be able to see difference between values? Thanks
data stats;
input @1 avisit $10. @9 avisitn armn armcd $ median q1 q3;
datalines;
Baseline 0 60 DummyA 5639 2909 7221.5
Baseline 0 70 DummyB 3876 2929 6587
Baseline 0 80 DummyC 5112 3284 6686
Week1 12 60 DummyA 3304 1961 6157.5
Week12 12 70 DummyB 3496 1717 5021.5
Week12 12 80 DummyC 4266.5 3436 6504.5
Week26 26 60 DummyA 3762 2409 6233
Week26 26 70 DummyB 4377 3380 6735
Week26 26 80 DummyC 4261 3242 6084
;
run;
proc sort data=stats out=sorted; by avisitn armcd; run;
proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One way is to add a small value to the xaxis variable.
data toplot; set sorted; by avisitn; if first.avisitn then counter=0; if avisitn>0 then avisitn=avisitn+counter; counter+0.1; /* if the 0.1 doesn't get the desired space try larger/smaller value*/ run; proc sgplot data=toplot noautolegend; series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9) group=armcd curvelabel; highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2) group=armcd; run;
The BY statement in a data step creates automatic variables First. and Last. for each variable on the by statement. These are numeric 1/0 and the 1 is treated as true. So you can test if a value is the first or last and reset or set values. The Counter+0.1; makes the variable Counter retained across iterations of the data step and if not the first of the Avisitn values will be available to make the numeric Avisitn slightly larger for each one in the group. The exception is that the 0 values do not get any increment though could if the "if avisit>0 then" were removed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/*You need add another two options:
groupdisplay= and clusterwidth=*/
proc sgplot data=sorted noautolegend;
series x=avisitn y=median / markers markerattrs=(symbol=circlefilled size=9)
group=armcd curvelabel groupdisplay=cluster clusterwidth=0.2;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2)
group=armcd groupdisplay=cluster clusterwidth=0.2;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for this. The issue is still how to add markers and legend .I am using this:
styleattrs Datasymbols=(circleFilled asterisk trianglefilled)
Datalinepatterns=(solid shortdash mediumdashshortdash)
DATACONTRASTCOLORS=(black black black);
and add legend, but it does not show the right legend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Details.
Markers WHERE?
Legend: what should the legend show? You say "does not show the right legend." so what is wrong with the legend you are getting? Without details it is very hard to provide suggestions.
Show your entire proc sgplot code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So I have 3 groups, datasymbols provide different symbol for each time point,datalinepatterns for lines between symbols.
If I use keylegend/ location=outside position=bottom;
each group have just datalinepatterns, but not datalinepatterns+datasymbol
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Let's try this again: Show the complete Proc SGplot code you are using.
@VioletaB wrote:
So I have 3 groups, datasymbols provide different symbol for each time point,datalinepatterns for lines between symbols.
If I use keylegend/ location=outside position=bottom;
each group have just datalinepatterns, but not datalinepatterns+datasymbol
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ods graphics/attrpriority=none;
proc sgplot data=sorted ;
styleattrs Datasymbols=(circleFilled asterisk trianglefilled)
Datalinepatterns=(solid shortdash mediumdashshortdash)
DATACONTRASTCOLORS=(black black black);
series x=avisitn y=median / markers markerattrs=(size=9) name='x'
group=armcd curvelabel groupdisplay=cluster clusterwidth=0.2;
highlow x=avisitn high=q3 low=q1 / lineattrs=(thickness=2)
group=armcd groupdisplay=cluster clusterwidth=0.2;
keylegend 'x' / location=outside position=bottom ;
run;