<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Fun With SAS ODS Graphics: Hexagon Map State-by-State 2024 Election Recap in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-Hexagon-Map-State-by-State-2024/m-p/951738#M25151</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UsPresidentialElection2024Cartogram.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102474i12F8377465307B9A/image-size/large?v=v2&amp;amp;px=999" role="button" title="UsPresidentialElection2024Cartogram.png" alt="UsPresidentialElection2024Cartogram.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://medium.com/data-visualization-weekly/awesome-new-data-visualization-works-dataviz-weekly-593c8487d83a" target="_self"&gt;DataViz Weekly&lt;/A&gt;&lt;SPAN&gt; Medium post pointing to a &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://www.anychart.com/blog/2024/11/08/us-election-maps/" target="_self"&gt;nice roundup of 2024 U.S. Election maps&lt;/A&gt;&lt;SPAN&gt;, as well as Flourish's neat &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://flourish.studio/blog/report-on-elections-with-flourish/" target="_self"&gt;16 Ways to Visualize US Election Data&lt;/A&gt;&lt;SPAN&gt;, prompted my above SAS ODS Graphics state-by-state hexagon recap of the 2024 Presidential election, which uses hexagonal images of Kamala Harris and Donald Trump (created using MS-Word - insert hexagon shape, rotate 90 degrees, insert cropped-to-fit width-and-height photos from Wikipedia as shape fill, save shapes as .png files).&amp;nbsp; And that's the last of &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-How-Many-States-Does-It-Take-to-Win-a/m-p/950006" target="_self"&gt;my 2024 Election Charts&lt;/A&gt;&lt;SPAN&gt; - back to Holiday-themed charts this week for Thanksgiving!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Fun With SAS ODS Graphics: Hexagon Map State-by-State 2024 Election Recap;

* Get Electoral College Votes and Most Recent Results by State
  https://www.nbcnews.com/politics/2024-elections/president-results;
proc import datafile='/home/ted.conway/PresidentialElectionResults2024.xlsx' out=ElectionResults dbms=xlsx replace;

* Get state name to state code mapping;
proc import datafile='/home/ted.conway/state2statecd.xlsx' out=state2statecd dbms=xlsx replace;

proc sql;                                             * Append state abbreviation (special join logic for split states, DC);
create table StateCodesElectionResults as
select statecd, winner, votes from 
(select state, case when harris&amp;gt;trump then 'Harris' else 'Trump' end as Winner, sum(votes) as Votes
 from ElectionResults group by 1, 2) er 
left join state2statecd s2c on translate(er.state,' ','123')=s2c.state or scan(er.state,-1,' ,')=s2c.statecd
order by statecd, votes desc;

data StateCodesElectionResultsDeduped;                * De-dupe split states, pick candidate with most votes as the winner;
set StateCodesElectionResults;
by statecd;
if first.statecd; 

data StateGrid;                                       * Get state x/y coordinates for hexagon (courtesy of Matt Chambers, sirvizalot.com/2016/05/how-to-small-multiple-tile-map-in.html);                                       
input statecode : $2. row column@@;
row=-row;                                             * Flip map's y-coordinates (FL at bottom, ME at top!);
ty=row-.5;
cards;
AK 0 0.5 ME 0 11.5        
VT 1 10 NH 1 11        
WA 2 1.5 MT 2 2.5 ND 2 3.5 MN 2 4.5 WI 2 5.5 MI 2 7.5 NY 2 9.5 MA 2 10.5 RI 2 11.5 
ID 3 2 WY 3 3 SD 3 4 IA 3 5 IL 3 6 IN 3 7 OH 3 8 PA 3 9 NJ 3 10 CT 3 11
OR 4 1.5 NV 4 2.5 CO 4 3.5 NE 4 4.5 MO 4 5.5 KY 4 6.5 WV 4 7.5 MD 4 8.5 DE 4 9.5 
CA 5 2 AZ 5 3 UT 5 4 KS 5 5 AR 5 6 TN 5 7 VA 5 8 NC 5 9 DC 5 12 
NM 6 3.5 OK 6 4.5 LA 6 5.5 MS 6 6.5 AL 6 7.5 SC 6 8.5    
TX 7 4 GA 7 8        
HI 8 0.5 FL 8 8.5 
;
run;

proc sql;                                             * Join state vote winner data with hexagon state x/y coordinates; 
create table states2map as                            /* Highlight states that flipped from Democrat to Republican in 2024 with plus (+) signs */
select *, case when statecd in ('AZ', 'GA', 'MI', 'NV', 'PA', 'WI') then '+'||trim(statecd)||'+' else statecd end as statecd2
from StateCodesElectionResultsDeduped t1
join stategrid t2 on t1.statecd=t2.statecode
order by t1.statecd;

data myattrmap;                                       * Specify images, colors assoicated with candidates;
input ID $ value $ markersymbol $ textcolor $;
datalines;
myid Harris harris blue
myid Trump trump red
;                                                     * Let's create a hexagon map (scatter/text plots using images of candidates)!;
ods graphics / width=21.5in height=16in noborder imagefmt=png;
proc sgplot data=states2map nowall dattrmap=myattrmap noautolegend noborder;
inset " " "2024 U.S. Presidential Election Results" / textattrs=(size=32pt) position=top;
inset "Plus signs (+) denote six states that flipped to Republican in 2024" / position=bottomright textattrs=(size=14pt);
symbolimage name=harris image='/home/ted.conway/harrishex.png'; * Kamala Harris photo (source: en.wikipedia.org/wiki/2024_United_States_presidential_election);
symbolimage name=trump image='/home/ted.conway/trumphex.png';   * Donald Trump photo (source: en.wikipedia.org/wiki/2024_United_States_presidential_election);
scatter x=column y=row / markerattrs=(size=78pt) attrid=myid group=winner; * Plot candidate images;
text x=column y=ty text=statecd2 / position=bottom attrid=myid group=winner textattrs=(size=12pt weight=bold) contributeoffsets=none strip; * Add state abbreviations below images;
xaxis display=none values=(.25 to 12.25);             * Suppress axes, limit bounds of axes;
yaxis display=none values=(0 to -9);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 24 Nov 2024 21:37:00 GMT</pubDate>
    <dc:creator>tc</dc:creator>
    <dc:date>2024-11-24T21:37:00Z</dc:date>
    <item>
      <title>Fun With SAS ODS Graphics: Hexagon Map State-by-State 2024 Election Recap</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-Hexagon-Map-State-by-State-2024/m-p/951738#M25151</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UsPresidentialElection2024Cartogram.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102474i12F8377465307B9A/image-size/large?v=v2&amp;amp;px=999" role="button" title="UsPresidentialElection2024Cartogram.png" alt="UsPresidentialElection2024Cartogram.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://medium.com/data-visualization-weekly/awesome-new-data-visualization-works-dataviz-weekly-593c8487d83a" target="_self"&gt;DataViz Weekly&lt;/A&gt;&lt;SPAN&gt; Medium post pointing to a &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://www.anychart.com/blog/2024/11/08/us-election-maps/" target="_self"&gt;nice roundup of 2024 U.S. Election maps&lt;/A&gt;&lt;SPAN&gt;, as well as Flourish's neat &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://flourish.studio/blog/report-on-elections-with-flourish/" target="_self"&gt;16 Ways to Visualize US Election Data&lt;/A&gt;&lt;SPAN&gt;, prompted my above SAS ODS Graphics state-by-state hexagon recap of the 2024 Presidential election, which uses hexagonal images of Kamala Harris and Donald Trump (created using MS-Word - insert hexagon shape, rotate 90 degrees, insert cropped-to-fit width-and-height photos from Wikipedia as shape fill, save shapes as .png files).&amp;nbsp; And that's the last of &lt;/SPAN&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-How-Many-States-Does-It-Take-to-Win-a/m-p/950006" target="_self"&gt;my 2024 Election Charts&lt;/A&gt;&lt;SPAN&gt; - back to Holiday-themed charts this week for Thanksgiving!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Fun With SAS ODS Graphics: Hexagon Map State-by-State 2024 Election Recap;

* Get Electoral College Votes and Most Recent Results by State
  https://www.nbcnews.com/politics/2024-elections/president-results;
proc import datafile='/home/ted.conway/PresidentialElectionResults2024.xlsx' out=ElectionResults dbms=xlsx replace;

* Get state name to state code mapping;
proc import datafile='/home/ted.conway/state2statecd.xlsx' out=state2statecd dbms=xlsx replace;

proc sql;                                             * Append state abbreviation (special join logic for split states, DC);
create table StateCodesElectionResults as
select statecd, winner, votes from 
(select state, case when harris&amp;gt;trump then 'Harris' else 'Trump' end as Winner, sum(votes) as Votes
 from ElectionResults group by 1, 2) er 
left join state2statecd s2c on translate(er.state,' ','123')=s2c.state or scan(er.state,-1,' ,')=s2c.statecd
order by statecd, votes desc;

data StateCodesElectionResultsDeduped;                * De-dupe split states, pick candidate with most votes as the winner;
set StateCodesElectionResults;
by statecd;
if first.statecd; 

data StateGrid;                                       * Get state x/y coordinates for hexagon (courtesy of Matt Chambers, sirvizalot.com/2016/05/how-to-small-multiple-tile-map-in.html);                                       
input statecode : $2. row column@@;
row=-row;                                             * Flip map's y-coordinates (FL at bottom, ME at top!);
ty=row-.5;
cards;
AK 0 0.5 ME 0 11.5        
VT 1 10 NH 1 11        
WA 2 1.5 MT 2 2.5 ND 2 3.5 MN 2 4.5 WI 2 5.5 MI 2 7.5 NY 2 9.5 MA 2 10.5 RI 2 11.5 
ID 3 2 WY 3 3 SD 3 4 IA 3 5 IL 3 6 IN 3 7 OH 3 8 PA 3 9 NJ 3 10 CT 3 11
OR 4 1.5 NV 4 2.5 CO 4 3.5 NE 4 4.5 MO 4 5.5 KY 4 6.5 WV 4 7.5 MD 4 8.5 DE 4 9.5 
CA 5 2 AZ 5 3 UT 5 4 KS 5 5 AR 5 6 TN 5 7 VA 5 8 NC 5 9 DC 5 12 
NM 6 3.5 OK 6 4.5 LA 6 5.5 MS 6 6.5 AL 6 7.5 SC 6 8.5    
TX 7 4 GA 7 8        
HI 8 0.5 FL 8 8.5 
;
run;

proc sql;                                             * Join state vote winner data with hexagon state x/y coordinates; 
create table states2map as                            /* Highlight states that flipped from Democrat to Republican in 2024 with plus (+) signs */
select *, case when statecd in ('AZ', 'GA', 'MI', 'NV', 'PA', 'WI') then '+'||trim(statecd)||'+' else statecd end as statecd2
from StateCodesElectionResultsDeduped t1
join stategrid t2 on t1.statecd=t2.statecode
order by t1.statecd;

data myattrmap;                                       * Specify images, colors assoicated with candidates;
input ID $ value $ markersymbol $ textcolor $;
datalines;
myid Harris harris blue
myid Trump trump red
;                                                     * Let's create a hexagon map (scatter/text plots using images of candidates)!;
ods graphics / width=21.5in height=16in noborder imagefmt=png;
proc sgplot data=states2map nowall dattrmap=myattrmap noautolegend noborder;
inset " " "2024 U.S. Presidential Election Results" / textattrs=(size=32pt) position=top;
inset "Plus signs (+) denote six states that flipped to Republican in 2024" / position=bottomright textattrs=(size=14pt);
symbolimage name=harris image='/home/ted.conway/harrishex.png'; * Kamala Harris photo (source: en.wikipedia.org/wiki/2024_United_States_presidential_election);
symbolimage name=trump image='/home/ted.conway/trumphex.png';   * Donald Trump photo (source: en.wikipedia.org/wiki/2024_United_States_presidential_election);
scatter x=column y=row / markerattrs=(size=78pt) attrid=myid group=winner; * Plot candidate images;
text x=column y=ty text=statecd2 / position=bottom attrid=myid group=winner textattrs=(size=12pt weight=bold) contributeoffsets=none strip; * Add state abbreviations below images;
xaxis display=none values=(.25 to 12.25);             * Suppress axes, limit bounds of axes;
yaxis display=none values=(0 to -9);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Nov 2024 21:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-Hexagon-Map-State-by-State-2024/m-p/951738#M25151</guid>
      <dc:creator>tc</dc:creator>
      <dc:date>2024-11-24T21:37:00Z</dc:date>
    </item>
  </channel>
</rss>

