- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to show data labels on the bar chart like in the image.
My code looks like:
proc sgplot data=mydata
styleattrs datacolors=(blue red) datalinepatterns=(solid);
vbar season_ / response=quantity
group=condition limitstat=stderr numstd=1 stat=mean
datalabel=quantity datalabelattrs=(size=12pt) datalabelpos=bottom
limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster;
.....
I would like to change the label "Ev (mean)" to another name I choose (for example just "mean"), does someone know if there is a way to do it?
Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Since you need more control, use the XAXISTABLE statement instead of the DATALABEL option to display your values. The code would look something like the following:
proc sgplot data=mydata styleattrs datacolors=(blue red) datalinepatterns=(solid); vbar season_ / response=quantity group=condition limitstat=stderr numstd=1 stat=mean limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster; xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside class=condition classdisplay=cluster label="Mean"; .....
There are additional option in the XAXISTABLE statement you might like. See the documentation for more details.
Hope this helps!
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Since you need more control, use the XAXISTABLE statement instead of the DATALABEL option to display your values. The code would look something like the following:
proc sgplot data=mydata styleattrs datacolors=(blue red) datalinepatterns=(solid); vbar season_ / response=quantity group=condition limitstat=stderr numstd=1 stat=mean limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster; xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside class=condition classdisplay=cluster label="Mean"; .....
There are additional option in the XAXISTABLE statement you might like. See the documentation for more details.
Hope this helps!
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is great, thank you for your help @DanH_sas !
Now I have another question: supposing I want to show also the frequency as a statistic, here is the code:
xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside position=bottom
class=condition classdisplay=cluster label="Mean" labelattrs=(size=12pt);
xaxistable quantity / stat=freq valueattrs=(size=12pt) location=inside position=bottom
class=condition classdisplay=cluster label="N" labelattrs=(size=12pt);
Now the frequency (which I call N) has two decimal values (see screenshot). Do you know if there is a way to change the format, for instance to an integer with 0 decimal values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The axis table is probably picking up the format from the "quantity" variable. You can work around this issue by using a little data step to copy the values from "quantity" to "quantity2" and setting a BEST. format on "quantity2". Then, use the "quantity2" variable for the FREQ axis table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content