- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to make a plot similar to this one, but I really have no idea how. I have four variable I want to include - sex, race, educ, and diet, and I want a variable called homoc on the y axis. Any ideas? Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data toplot; set sashelp.class; length vn $ 10; vn='Sex'; category=put(sex,$5.); output; vn='Age'; category=put(age,f5.); output; run; proc sgpanel data=toplot noautolegend; panelby vn/layout=columnlattice onepanel uniscale=row noheader; vbox weight/category=category group=vn; rowaxis display=(nolabel); colaxis display=(nolabel); run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One way involves reshaping the data bit. Here is an example using a data set you should have that will allow you to run the code.
data toplot; set sashelp.class; length vn $ 10; vn='Sex'; category=put(sex,$5.); output; vn='Age'; category=put(age,f5.); output; run; proc sgplot data=toplot noautolegend; vbox weight /group=vn category=category; xaxis label=' '; run;
The data step makes a duplicate of your analysis variable(s), in this case we could use either or both of the Height and Weight variables. We add a variable for the Group role using the name of the variable. This sets the colors for related values the same. We also add a variable for the Category role, which means each value will get a separate box created. I made sure the text created has the same length to avoid possible problems. The Output statement if you haven't used it, tells the program to write to the data set when encountered. This is where the values for each analysis variable get duplicated.
The Sgplot uses the created data set. Since your example doesn't show a key for the groups (Probably because your text is fairly explanatory) is suppress the automatic legend that would have the values of the Group variable as key to the colors. The Xaxis statement also suppresses any axis label. The vertical axis label will by default be the label associated with your analysis variable.
A REFLINE statement can add a reference line. I'm not sure if you actually wanted one, or where and I don't have your data to make any guess. A simple: REFLINE 50; would place a horizontal line across the graph at the Y axis value of 50. There are options to set line types and labels if desired.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data toplot; set sashelp.class; length vn $ 10; vn='Sex'; category=put(sex,$5.); output; vn='Age'; category=put(age,f5.); output; run; proc sgpanel data=toplot noautolegend; panelby vn/layout=columnlattice onepanel uniscale=row noheader; vbox weight/category=category group=vn; rowaxis display=(nolabel); colaxis display=(nolabel); run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content