<?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: Varying the size of a boxplot in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Varying-the-size-of-a-boxplot/m-p/249091#M9044</link>
    <description>&lt;P&gt;PROC BOXPLOT uses the GTL BOXPLOTPARM statement to render the box plot. &amp;nbsp;BOXPLOTPARM supports the BOXWIDTH statistic value, which allows this feature. &amp;nbsp;PROC SGPLOT does not support this feature, as it is seen to be beyond what is commonly requested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you are willing write a bit off GTL code, you can do this. &amp;nbsp;First, run the regular SGPLOT code with ODS OUTPUT SGPLOT=boxdata; statement. &amp;nbsp;This will save the data needed to plot the boxplot into the "BoxData" data set. &amp;nbsp;Examine this data set and you will see three computed columns ending with "_X", "_Y" and "_ST". &amp;nbsp;"_X" is the category variable. &amp;nbsp;"_ST" is the statistic column which contains the box plot features such as "Q!", "Q3" and so on. &amp;nbsp;These along with corresponding "_Y" values are used to display the boxes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BoxPlotParm statement also supports the "BOXWIDTH" statistic, with corresponding value 0.0 - 1.0. &amp;nbsp;You will need to compute the appropriate value for BoxWidth, and insert it into the data set. &amp;nbsp;Here I have computed BoxWidth based on N. &amp;nbsp;See graph and code below. &amp;nbsp;Value of N is also displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1820i1EBF68772270F381/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="BoxWidth2.png" title="BoxWidth2.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Get Box Plot graph&amp;nbsp;data--*/&lt;/P&gt;
&lt;P&gt;ods output sgplot=boxdata;&lt;BR /&gt;proc sgplot data=sashelp.cars;&lt;BR /&gt; vbox mpg_city / category=type;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Find largest N value--*/&lt;BR /&gt;data null;&lt;BR /&gt;&amp;nbsp; retain maxN 0;&lt;BR /&gt;&amp;nbsp; set boxdata end=last;&lt;BR /&gt;&amp;nbsp; if box_mpg_city_x_type_sortorder_st eq 'N' then maxN=max(maxN, BOX_MPG_CITY_X_TYPE_SORTORDER__Y);&lt;BR /&gt;&amp;nbsp; if last then call symput("MaxN", maxN);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=boxdata;&lt;BR /&gt; by BOX_MPG_CITY_X_TYPE_SORTORDER__X;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Add BoxWidth stat to data--*/&lt;/P&gt;
&lt;P&gt;data boxdataWidth;&lt;BR /&gt;&amp;nbsp; set boxdata(where=(BOX_MPG_CITY_X_TYPE_SORTORDER__X ne ''));&lt;BR /&gt;&amp;nbsp; by BOX_MPG_CITY_X_TYPE_SORTORDER__X;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if box_mpg_city_x_type_sortorder_st eq 'N' then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; N=BOX_MPG_CITY_X_TYPE_SORTORDER__Y;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; boxwidth=0.05+ 0.5* n/&amp;amp;MaxN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; box_mpg_city_x_type_sortorder_st='BOXWIDTH';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; BOX_MPG_CITY_X_TYPE_SORTORDER__Y=boxwidth;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; else output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Define Box Plot template--*/&lt;/P&gt;
&lt;P&gt;proc template;&lt;BR /&gt;&amp;nbsp; define statgraph BoxWidth;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; begingraph;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; entrytitle 'Mileage by Type';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; layout overlay;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; boxplotparm x=BOX_MPG_CITY_X_TYPE_SORTORDER__X y=BOX_MPG_CITY_X_TYPE_SORTORDER__Y&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stat=BOX_MPG_CITY_X_TYPE_SORTORDER_ST;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; scatterplot x=BOX_MPG_CITY_X_TYPE_SORTORDER__X y=eval(BOX_MPG_CITY_X_TYPE_SORTORDER__Y*0+5) /&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; markercharacter=n;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; endlayout;&lt;BR /&gt;&amp;nbsp; endgraph;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Render graph--*/&lt;BR /&gt;ods graphics / reset width=5in height=3in imagename='BoxWidth';&lt;BR /&gt;proc sgrender data=boxdataWidth template=BoxWidth;&lt;BR /&gt;format n 3.0;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2016 23:35:11 GMT</pubDate>
    <dc:creator>Jay54</dc:creator>
    <dc:date>2016-02-09T23:35:11Z</dc:date>
    <item>
      <title>Varying the size of a boxplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Varying-the-size-of-a-boxplot/m-p/248944#M9038</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm using PROC SGPLOT and I'd like to create a box plot with box plots&amp;nbsp;whose widths vary proportionately with the group size.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In PROC BOXPLOT I'm able to do this using&amp;nbsp;boxwidthscale = 1, but can't seem to find an equivalent in PROC SGPLOT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone know of any such code&amp;nbsp;that can do this in SGPLOT?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And I'm using SAS 9.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2016 16:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Varying-the-size-of-a-boxplot/m-p/248944#M9038</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-02-09T16:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Varying the size of a boxplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Varying-the-size-of-a-boxplot/m-p/249091#M9044</link>
      <description>&lt;P&gt;PROC BOXPLOT uses the GTL BOXPLOTPARM statement to render the box plot. &amp;nbsp;BOXPLOTPARM supports the BOXWIDTH statistic value, which allows this feature. &amp;nbsp;PROC SGPLOT does not support this feature, as it is seen to be beyond what is commonly requested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you are willing write a bit off GTL code, you can do this. &amp;nbsp;First, run the regular SGPLOT code with ODS OUTPUT SGPLOT=boxdata; statement. &amp;nbsp;This will save the data needed to plot the boxplot into the "BoxData" data set. &amp;nbsp;Examine this data set and you will see three computed columns ending with "_X", "_Y" and "_ST". &amp;nbsp;"_X" is the category variable. &amp;nbsp;"_ST" is the statistic column which contains the box plot features such as "Q!", "Q3" and so on. &amp;nbsp;These along with corresponding "_Y" values are used to display the boxes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BoxPlotParm statement also supports the "BOXWIDTH" statistic, with corresponding value 0.0 - 1.0. &amp;nbsp;You will need to compute the appropriate value for BoxWidth, and insert it into the data set. &amp;nbsp;Here I have computed BoxWidth based on N. &amp;nbsp;See graph and code below. &amp;nbsp;Value of N is also displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1820i1EBF68772270F381/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="BoxWidth2.png" title="BoxWidth2.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Get Box Plot graph&amp;nbsp;data--*/&lt;/P&gt;
&lt;P&gt;ods output sgplot=boxdata;&lt;BR /&gt;proc sgplot data=sashelp.cars;&lt;BR /&gt; vbox mpg_city / category=type;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Find largest N value--*/&lt;BR /&gt;data null;&lt;BR /&gt;&amp;nbsp; retain maxN 0;&lt;BR /&gt;&amp;nbsp; set boxdata end=last;&lt;BR /&gt;&amp;nbsp; if box_mpg_city_x_type_sortorder_st eq 'N' then maxN=max(maxN, BOX_MPG_CITY_X_TYPE_SORTORDER__Y);&lt;BR /&gt;&amp;nbsp; if last then call symput("MaxN", maxN);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=boxdata;&lt;BR /&gt; by BOX_MPG_CITY_X_TYPE_SORTORDER__X;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Add BoxWidth stat to data--*/&lt;/P&gt;
&lt;P&gt;data boxdataWidth;&lt;BR /&gt;&amp;nbsp; set boxdata(where=(BOX_MPG_CITY_X_TYPE_SORTORDER__X ne ''));&lt;BR /&gt;&amp;nbsp; by BOX_MPG_CITY_X_TYPE_SORTORDER__X;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if box_mpg_city_x_type_sortorder_st eq 'N' then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; N=BOX_MPG_CITY_X_TYPE_SORTORDER__Y;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; boxwidth=0.05+ 0.5* n/&amp;amp;MaxN;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; box_mpg_city_x_type_sortorder_st='BOXWIDTH';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; BOX_MPG_CITY_X_TYPE_SORTORDER__Y=boxwidth;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; else output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Define Box Plot template--*/&lt;/P&gt;
&lt;P&gt;proc template;&lt;BR /&gt;&amp;nbsp; define statgraph BoxWidth;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; begingraph;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; entrytitle 'Mileage by Type';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; layout overlay;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; boxplotparm x=BOX_MPG_CITY_X_TYPE_SORTORDER__X y=BOX_MPG_CITY_X_TYPE_SORTORDER__Y&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stat=BOX_MPG_CITY_X_TYPE_SORTORDER_ST;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; scatterplot x=BOX_MPG_CITY_X_TYPE_SORTORDER__X y=eval(BOX_MPG_CITY_X_TYPE_SORTORDER__Y*0+5) /&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; markercharacter=n;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; endlayout;&lt;BR /&gt;&amp;nbsp; endgraph;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*--Render graph--*/&lt;BR /&gt;ods graphics / reset width=5in height=3in imagename='BoxWidth';&lt;BR /&gt;proc sgrender data=boxdataWidth template=BoxWidth;&lt;BR /&gt;format n 3.0;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2016 23:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Varying-the-size-of-a-boxplot/m-p/249091#M9044</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2016-02-09T23:35:11Z</dc:date>
    </item>
  </channel>
</rss>

