<?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 Re: Assign Specific Colors to Scatterplot in PROC SGPLOT in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/555710#M18074</link>
    <description>&lt;P&gt;Here's one way to do it, using an attribute map, a user-defined format, and also adding 'fake' data to guarantee it always has all the categories in the legend (even if there aren't any hurricanes of that category that year) ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname storms "D:\public\noaa";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fake;&lt;BR /&gt;input wind_mph;&lt;BR /&gt;datalines;&lt;BR /&gt;30&lt;BR /&gt;40&lt;BR /&gt;75&lt;BR /&gt;100&lt;BR /&gt;115&lt;BR /&gt;135&lt;BR /&gt;160&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro hurricaneplot(year);&lt;BR /&gt;proc format;&lt;BR /&gt;value cat&lt;BR /&gt;low - &amp;lt; 38 = 'TD'&lt;BR /&gt;38 - &amp;lt; 73 = 'TS'&lt;BR /&gt;73 - &amp;lt; 95 = '1'&lt;BR /&gt;95 - &amp;lt; 110 = '2'&lt;BR /&gt;110 - &amp;lt; 129 = '3'&lt;BR /&gt;129 - &amp;lt; 156 = '4'&lt;BR /&gt;156 - high = '5'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data myattrs;&lt;BR /&gt;id="some_id";&lt;BR /&gt;value='TD'; markercolor="cx52b1ff"; output;&lt;BR /&gt;value='TS'; markercolor="cx00f8f1"; output;&lt;BR /&gt;value='1'; markercolor="cxffffc6"; output;&lt;BR /&gt;value='2'; markercolor="cxffe369"; output;&lt;BR /&gt;value='3'; markercolor="cxffb935"; output;&lt;BR /&gt;value='4'; markercolor="cxff8318"; output;&lt;BR /&gt;value='5'; markercolor="cxff290a"; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp; set fake storms.noaa_allstorms (where=(basin='NA' and year=&amp;amp;year));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;title1 "Northern Atlantic Hurricanes in &amp;amp;year";&lt;BR /&gt;proc sgplot data=temp dattrmap=myattrs noautolegend;&lt;BR /&gt;format wind_mph cat.;&lt;BR /&gt;series x=long y=lat / group=unique_id break lineattrs=(color=grey);&lt;BR /&gt;scatter x=long y=lat / group=wind_mph attrid=some_id&lt;BR /&gt;markerattrs=(size=6 symbol=Circle) name='markers';&lt;BR /&gt;keylegend 'markers' / title="Storm Classification";&lt;BR /&gt;xaxis label="Longitude" values=(-110 to 0 by 10);&lt;BR /&gt;yaxis label="Latitude" values=(0 to 70 by 10);&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%hurricaneplot(2016);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hurricane_example.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29170i7E3EFE1C666320FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="hurricane_example.png" alt="hurricane_example.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 18:18:57 GMT</pubDate>
    <dc:creator>GraphGuy</dc:creator>
    <dc:date>2019-05-02T18:18:57Z</dc:date>
    <item>
      <title>Assign Specific Colors to Scatterplot in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/554788#M18055</link>
      <description>&lt;P&gt;I have written a macro that takes storm data from a particular year and then plots points of latitude and longitude for the storms colored by what type they were (status variable). Many years do not have every type of storm, so when I change the year in the macro, the legend and scatter plot colors are almost always different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally, I would like to be able to assign a color to each level of the "status" variable and have it be consistent from year to year (for example, I want to keep that bright blue for all graphs that have "HU").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code and a picture of the plot for the year 2017. I'm using a version of SAS 9.4 available through my university (it is limited and missing several libraries).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro hurricaneMap(year=2017);
proc sgplot data=weather3;
	series x=long y=lat / group=cyclone_num lineattrs=(pattern=Solid color=grey);
	scatter x=long y=lat / group=status markerattrs=(size=6 symbol=Circle);
	keylegend / title="Storm Classification" exclude=("01" "02" "03" "04" 
	"05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" 
        "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31");
	xaxis label="Longitude" values=(-110 to 0 by 10);
	yaxis label="Latitude" values=(0 to 70 by 10);
	title "&amp;amp;year. Atlantic Basin Storm Summary Map";
	where year=&amp;amp;year.;
run;

%mend;

%hurricaneMap(year=2017);&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2017SummaryMap.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29102i41C0502FF41B311B/image-size/large?v=v2&amp;amp;px=999" role="button" title="2017SummaryMap.png" alt="2017SummaryMap.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 17:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/554788#M18055</guid>
      <dc:creator>sagendtj</dc:creator>
      <dc:date>2019-04-29T17:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Specific Colors to Scatterplot in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/554821#M18056</link>
      <description>&lt;P&gt;You need a data attribute map, essentially, you create a data set with the status and colours you'd like them and provide that to SGPLOT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examples and specifications are here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=grstatproc&amp;amp;docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272104"&gt;@sagendtj&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have written a macro that takes storm data from a particular year and then plots points of latitude and longitude for the storms colored by what type they were (status variable). Many years do not have every type of storm, so when I change the year in the macro, the legend and scatter plot colors are almost always different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, I would like to be able to assign a color to each level of the "status" variable and have it be consistent from year to year (for example, I want to keep that bright blue for all graphs that have "HU").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is my code and a picture of the plot for the year 2017. I'm using a version of SAS 9.4 available through my university (it is limited and missing several libraries).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro hurricaneMap(year=2017);
proc sgplot data=weather3;
	series x=long y=lat / group=cyclone_num lineattrs=(pattern=Solid color=grey);
	scatter x=long y=lat / group=status markerattrs=(size=6 symbol=Circle);
	keylegend / title="Storm Classification" exclude=("01" "02" "03" "04" 
	"05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" 
        "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31");
	xaxis label="Longitude" values=(-110 to 0 by 10);
	yaxis label="Latitude" values=(0 to 70 by 10);
	title "&amp;amp;year. Atlantic Basin Storm Summary Map";
	where year=&amp;amp;year.;
run;

%mend;

%hurricaneMap(year=2017);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2017SummaryMap.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29102i41C0502FF41B311B/image-size/large?v=v2&amp;amp;px=999" role="button" title="2017SummaryMap.png" alt="2017SummaryMap.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 19:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/554821#M18056</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-29T19:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Specific Colors to Scatterplot in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/555710#M18074</link>
      <description>&lt;P&gt;Here's one way to do it, using an attribute map, a user-defined format, and also adding 'fake' data to guarantee it always has all the categories in the legend (even if there aren't any hurricanes of that category that year) ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname storms "D:\public\noaa";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fake;&lt;BR /&gt;input wind_mph;&lt;BR /&gt;datalines;&lt;BR /&gt;30&lt;BR /&gt;40&lt;BR /&gt;75&lt;BR /&gt;100&lt;BR /&gt;115&lt;BR /&gt;135&lt;BR /&gt;160&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro hurricaneplot(year);&lt;BR /&gt;proc format;&lt;BR /&gt;value cat&lt;BR /&gt;low - &amp;lt; 38 = 'TD'&lt;BR /&gt;38 - &amp;lt; 73 = 'TS'&lt;BR /&gt;73 - &amp;lt; 95 = '1'&lt;BR /&gt;95 - &amp;lt; 110 = '2'&lt;BR /&gt;110 - &amp;lt; 129 = '3'&lt;BR /&gt;129 - &amp;lt; 156 = '4'&lt;BR /&gt;156 - high = '5'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data myattrs;&lt;BR /&gt;id="some_id";&lt;BR /&gt;value='TD'; markercolor="cx52b1ff"; output;&lt;BR /&gt;value='TS'; markercolor="cx00f8f1"; output;&lt;BR /&gt;value='1'; markercolor="cxffffc6"; output;&lt;BR /&gt;value='2'; markercolor="cxffe369"; output;&lt;BR /&gt;value='3'; markercolor="cxffb935"; output;&lt;BR /&gt;value='4'; markercolor="cxff8318"; output;&lt;BR /&gt;value='5'; markercolor="cxff290a"; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp; set fake storms.noaa_allstorms (where=(basin='NA' and year=&amp;amp;year));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;title1 "Northern Atlantic Hurricanes in &amp;amp;year";&lt;BR /&gt;proc sgplot data=temp dattrmap=myattrs noautolegend;&lt;BR /&gt;format wind_mph cat.;&lt;BR /&gt;series x=long y=lat / group=unique_id break lineattrs=(color=grey);&lt;BR /&gt;scatter x=long y=lat / group=wind_mph attrid=some_id&lt;BR /&gt;markerattrs=(size=6 symbol=Circle) name='markers';&lt;BR /&gt;keylegend 'markers' / title="Storm Classification";&lt;BR /&gt;xaxis label="Longitude" values=(-110 to 0 by 10);&lt;BR /&gt;yaxis label="Latitude" values=(0 to 70 by 10);&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%hurricaneplot(2016);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hurricane_example.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29170i7E3EFE1C666320FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="hurricane_example.png" alt="hurricane_example.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 18:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/555710#M18074</guid>
      <dc:creator>GraphGuy</dc:creator>
      <dc:date>2019-05-02T18:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Specific Colors to Scatterplot in PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/555725#M18075</link>
      <description>&lt;P&gt;If you have a situation like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13585"&gt;@GraphGuy&lt;/a&gt;&amp;nbsp;, where you want a consistent legend of your attrmap, even when data is not present, you can set SHOW=ATTRMAP in your attrmap dataset. This will override the legend normally generated from the plot content, and you will not have to create any "placeholder" data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Dan&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 18:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Assign-Specific-Colors-to-Scatterplot-in-PROC-SGPLOT/m-p/555725#M18075</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2019-05-02T18:53:42Z</dc:date>
    </item>
  </channel>
</rss>

