Data visualization with SAS programming

Grouped pie Chart and barplot comparing overall vs subset data

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Grouped pie Chart and barplot comparing overall vs subset data

[ Edited ]

Hi,

 

I want to compare overall data with a subset.

 

I could do this overlaying histograms thanks to these great answers.

That was for continuous data. Can the same be done with nominal and ordinal data in a grouped Pie chart or barplot?

 

Thanks


Accepted Solutions
Solution
‎11-17-2015 05:34 AM
Frequent Contributor
Posts: 108

Re: Grouped pie Chart and barplot comparing overall vs subset data

I think you should use butterfly chat , that is mush better .Just give a search ..There is a great artical on this.

View solution in original post


All Replies
Frequent Contributor
Posts: 108

Re: Grouped pie Chart and barplot comparing overall vs subset data

Pls give an example Chart what you are looking for and sample data.
SAS Super FREQ
Posts: 1,080

Re: Grouped pie Chart and barplot comparing overall vs subset data

If your data is grouped, and you want to compare the values side by side by Category, you can use the Proc SGPLOT VBAR statement or the Proc GCHART VBAR statement. 

 

proc sgplot data=sashelp.cars;
  vbar origin / response=mpg_city group=type groupdisplay=cluster stat=mean;
run;

 

Contributor
Posts: 41

Re: Grouped pie Chart and barplot comparing overall vs subset data

Thanks for answering.

 

This is not exactly what I'm looking for. I want to compare the distribution of a subgroup with the overall distribution.

 

Let's take an example.

Assuming I have different clusters of customers, I want to see what are the characteristics of each one. 

This can be done by comparing the distribution of each cluster with the overall distribution.

For example, for cluster1, I compare its countries' proportions to all data countiries' proportions.

A pie chart grouping both proportions can be visually easier to compare than two side by side pie charts.

 

Hope my example is clear

 

Solution
‎11-17-2015 05:34 AM
Frequent Contributor
Posts: 108

Re: Grouped pie Chart and barplot comparing overall vs subset data

I think you should use butterfly chat , that is mush better .Just give a search ..There is a great artical on this.
SAS Super FREQ
Posts: 889

Re: Grouped pie Chart and barplot comparing overall vs subset data

+1 for the butterfly chart. Here is an example: http://support.sas.com/kb/35/051.html

 

Contributor
Posts: 41

Re: Grouped pie Chart and barplot comparing overall vs subset data

Thx @pearsoninst and @DanH_sas ! Great idea. 

 

However, I didn't find yet how to do this with all the data and a subset in the same graphic. And this is the hardest part.

I think it can be done with proc template. 

 

SAS Super FREQ
Posts: 889

Re: Grouped pie Chart and barplot comparing overall vs subset data

Regardless of whether you use SGPLOT or GTL/SGRENDER, the data manipulation is the same:

1. Create a dataset with the subset data extracted from the original data, keeping only the columns necessary for the chart.

2. Rename the kept columns in the new dataset to something different from the orginal data column names.

3. Create a new dataset that is a "straight" merge (not "match-merge") of the subset data and the original data.

4. Use this merged dataset in either SGPLOT or SGRENDER.

 

Hope this helps!

Dan

SAS Super FREQ
Posts: 1,080

Re: Grouped pie Chart and barplot comparing overall vs subset data

One benefit with GTL is you can use the EVAL feature using IFC and IFN functions (and othe rways) to do subsetting of data on the fly inside the template.

Contributor
Posts: 41

Re: Grouped pie Chart and barplot comparing overall vs subset data

Thank you @pearsoninst@DanH_sas and @Sanjay_SAS for your help. Very instructive !

 

I finally used a butterfly plot to compare nominal variables. I used the eval function in GTL to keep values related to a specific filter variable's modality, and then compare them to overall values.

 

Butterfly plot is finally clearer and easier to compare than a pie chart.

 

I created a macro to automate all this so that it can be reusable.

 

Thanks !

Frequent Contributor
Posts: 108

Re: Grouped pie Chart and barplot comparing overall vs subset data

Great Job majdi_ka .. Keep it up and all the best ...
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 660 views
  • 5 likes
  • 4 in conversation