BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

Viz41Knockoff.png

 

After seeing Ferdio's creative "1 dataset 100 visualizations" project, what was I supposed to do - NOT try to knockoff one of them using SAS ODS Graphics? 😀 Code below (results above) inspired by Viz #41, a dot plot of a simple World Heritage Sites dataset.

 

* Fun With SAS ODS Graphics: Attempt to knockoff Viz #41 (World Heritage Sites dot plot) from Ferdio's creative "1 dataset 100 visualizations" project
  Inspired by 100.datavizproject.com/data-type/viz41 100.datavizproject.com from ferdio.com;

data viz41;                                      * Get 2004+2022 World Heritage Sites data for Norway, Denmark, Sweden; 
array countries{*} $ country1-country3;          * Array to hold 3 countries and # sites for reshaping; 
array sites{*} sites1-sites3;            
input title $80.;                                * Get description of data;
input country1-country3;                         * Grab  3 country names;
do row=1 to 2;                                   * Read rows with data for 2004 and 2022; 
  input yr sites1-sites3; 
  do col=1 to 3;                                 * And for each year/country...;                          
    country=countries{col}; 
    do y=1 to sites{col}; output; end;           * ...output one observation ("dot") for of its N sites for dot plot; 
  end;
end;                                             * Inline data from 100.datavizproject.com follows;
datalines;
     Number of World Heritage Sites
       Norway   Denmark   Sweden
2004        5         4       13    
2022        8        10       15  
;
proc sort; by yr country;                        * Sort data in ascending order by year/country;  

proc format;                                     * Country names + abbreviations;
value $countryF "Denmark"="DK" "Norway"="NO" "Sweden"="SE";

proc sgpanel data=viz41 noautolegend pad=48pt;   * Make a "dot strip" scatter plot;
panelby yr / onepanel layout=columnlattice columns=2 colheaderpos=bottom Headerattrs=(weight=bold) noborder nowall headerbackcolor=white noheaderborder novarname;
styleattrs datacontrastcolors=(red black blue);  * Contrasting colors for each country;
scatter x=country y=y / group=country markerattrs=(symbol=circlefilled size=14pt); * Plot one "dot" per site; 
colaxis display=(noticks noline nolabel) offsetmin=.25 offsetmax=.25;
rowaxis display=none offsetmin=.05 offsetmax=.05;
format country $countryF.;                       * Print country abbreviation instead of full name;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

With respect, I don't think this is a good visualization that is worthy of being reproduced. With no vertical axis, we are forced to count the number of dots if we want to know the number of sites in each country.

 

It seems like a simple bar chart is an easier and more effective presentation of these data. No doubt this is one of the "100 visualizations" that are considered. 

 

You transposed the data from wide to long in the DATA step. I decided to use PROC TRANSPOSE, but either will work. 

 

data sites;
input Year Norway   Denmark   Sweden;
datalines;
2004        5         4       13    
2022        8        10       15  
;

/* Transpose the variables from wide to long format */
proc transpose data=sites
   out=long(rename=(Col1=NumSites)) name=Country;                    
   by Year;                   /* for each subject */
   var Norway Denmark Sweden; /* make a row for these variables */
run;

title "World Heritage Sites in Scandinavia";
proc sgplot data=long;
   vbar Year / response=NumSites group=Country groupdisplay=cluster;
   label NumSites="Number of World Heritage Sites"
         Country="Country";
   xaxis display=(nolabel);
   yaxis integer grid;
run;

SGPlot10.png

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

With respect, I don't think this is a good visualization that is worthy of being reproduced. With no vertical axis, we are forced to count the number of dots if we want to know the number of sites in each country.

 

It seems like a simple bar chart is an easier and more effective presentation of these data. No doubt this is one of the "100 visualizations" that are considered. 

 

You transposed the data from wide to long in the DATA step. I decided to use PROC TRANSPOSE, but either will work. 

 

data sites;
input Year Norway   Denmark   Sweden;
datalines;
2004        5         4       13    
2022        8        10       15  
;

/* Transpose the variables from wide to long format */
proc transpose data=sites
   out=long(rename=(Col1=NumSites)) name=Country;                    
   by Year;                   /* for each subject */
   var Norway Denmark Sweden; /* make a row for these variables */
run;

title "World Heritage Sites in Scandinavia";
proc sgplot data=long;
   vbar Year / response=NumSites group=Country groupdisplay=cluster;
   label NumSites="Number of World Heritage Sites"
         Country="Country";
   xaxis display=(nolabel);
   yaxis integer grid;
run;

SGPlot10.png

tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

@Rick_SAS: Good suggestions + observations, as always. Yes, Ferdio did include some more fully-labeled bar charts in their 100-data-visualizions-on-the-wall compilation and issued a caveat suggesting Viz #41 was more about design whimsy than practicality ("A dot plot or dot chart visualizing the exact number of World Heritage sites for each year and country. No axis or labels used for simplicity, so the numbers will have to be counted manually.").

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 505 views
  • 4 likes
  • 2 in conversation