<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Graphics &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/category/graphics/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Wed, 19 Mar 2025 19:40:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Exploring Categorical Data in GAUSS 25</title>
		<link>https://www.aptech.com/blog/exploring-categorical-data-in-gauss-25/</link>
					<comments>https://www.aptech.com/blog/exploring-categorical-data-in-gauss-25/#respond</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Mon, 17 Mar 2025 16:19:08 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11585145</guid>

					<description><![CDATA[Categorical data plays a key role in data analysis, offering a structured way to capture qualitative relationships. Before running any models, simply examining the distribution of categorical data can provide valuable insights into underlying patterns.

In <a href="https://www.aptech.com/blog/gauss25/" target="_blank" rel="noopener">GAUSS 25</a>, these functions received significant enhancements, making them more powerful and user-friendly. In this post, we'll explore these improvements and demonstrate their practical applications.

Whether summarizing survey responses or exploring demographic trends, fundamental statistical tools, such as frequency counts and tabulations, help reveal these patterns.

]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Categorical data plays a key role in data analysis, offering a structured way to capture qualitative relationships. Before running any models, simply examining the distribution of categorical data can provide valuable insights into underlying patterns.</p>
<p>Whether summarizing survey responses or exploring demographic trends, fundamental statistical tools, such as frequency counts and tabulations, help reveal these patterns.</p>
<p>GAUSS offers several tools for summarizing and visualizing categorical data, including:</p>
<ul>
<li><a href="https://docs.aptech.com/gauss/tabulate.html" target="_blank" rel="noopener">tabulate</a>: Quickly compute cross-tabulations and summary tables.</li>
<li><a href="https://docs.aptech.com/gauss/frequency.html" target="_blank" rel="noopener">frequency</a>: Generate frequency counts and relative frequencies.</li>
<li><a href="https://docs.aptech.com/gauss/plotfreq.html" target="_blank" rel="noopener">plotFreq</a>: Create visual representations of frequency distributions.</li>
</ul>
<p>In <a href="https://www.aptech.com/blog/gauss25/" target="_blank" rel="noopener">GAUSS 25</a>, these functions received significant enhancements, making them more powerful and user-friendly. In this post, we'll explore these improvements and demonstrate their practical applications.</p>
<h2 id="frequency-counts">Frequency Counts</h2>
<p>The GAUSS <code>frequency</code> function generates frequency tables for categorical variables. In GAUSS 25, it has been enhanced to utilize metadata from <a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">dataframes</a>, automatically detecting and displaying variable names. Additionally, the function now includes an option to sort the frequency table, making it easier to analyze distributions.</p>
<h3 id="example-counting-product-categories">Example: Counting Product Categories</h3>
<p>For this example, we'll use a hypothetical dataset containing 50 observations of two categorical variables: <em>Product_Type</em> and <em>Region</em>. You can download the dataset here.</p>
<p>To start, we'll load the data using <a href="https://docs.aptech.com/gauss/loadd.html" target="_blank" rel="noopener">loadd</a>:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Sample product sales data
*/
// Import sales dataframe
product_data = loadd(__FILE_DIR $+ "product_data.csv");

// Preview data
head(product_data);</code></pre>
<pre>    Product_Type           Region
     Electronics             East
      Home Goods             West
       Furniture            North
            Toys             East
      Home Goods            North</pre>
<p>Next, we will compute the frequency counts of the <em>Product_Type</em> variable:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Compute frequency counts
frequency(product_data, "Product_Type");</code></pre>
<pre>=============================================
   Product_Type     Count   Total %    Cum. %
=============================================

       Clothing         8        16        16
    Electronics        13        26        42
      Furniture        10        20        62
     Home Goods         7        14        76
           Toys        12        24       100
=============================================
          Total        50       100</pre>
<p>We can also generate a sorted frequency table, using the optional sorting argument:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Compute frequency counts
frequency(product_data, "Product_Type", 1);</code></pre>
<pre>=============================================
   Product_Type     Count   Total %    Cum. %
=============================================

    Electronics        13        26        26
           Toys        12        24        50
      Furniture        10        20        70
       Clothing         8        16        86
     Home Goods         7        14       100
=============================================
          Total        50       100  </pre>
<h2 id="tabulating-categorical-data">Tabulating Categorical Data</h2>
<p>While frequency counts help us understand individual categories, the <code>tabulate</code> function allows us to explore relationships between categorical variables. This function performs cross-tabulations, offering deeper insights into categorical distributions. In GAUSS 25, it was enhanced with new options for calculating row and column percentages, making comparisons easier.</p>
<h3 id="example-cross-tabulating-product-type-and-region">Example: Cross-Tabulating Product Type and Region</h3>
<p>Now let's look at the relationship between <em>Product_Type</em> and <em>Region</em>. </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Generate cross-tabulation
call tabulate(product_data, "Product_Type ~ Region");</code></pre>
<pre>=====================================================================================
   Product_Type                              Region                             Total
=====================================================================================
                      East          North          South           West

       Clothing          1              5              1              1             8
    Electronics          5              1              5              2            13
      Furniture          3              3              1              3            10
     Home Goods          1              3              2              1             7
           Toys          4              3              2              3            12
          Total         14             15             11             10            50

=====================================================================================</pre>
<p>By default, the <code>tabulate</code> function generates absolute counts. However, in some cases, relative frequencies provide more meaningful insights. In GAUSS 25, <code>tabulate</code> now includes options to calculate row and column percentages, making it easier to compare distributions across categories.</p>
<p>This is done using the <code>tabControl</code> structure and the <em>rowPercent</em> or <em>columnPercent</em> members. </p>
<ul>
<li><strong>Row percentages</strong> show how the distribution of product types varies across regions.</li>
<li><strong>Column percentages</strong> highlight the composition of product types within each region.</li>
</ul>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Relative tabulations
*/ 
struct tabControl tCtl;
tCtl = tabControlCreate();

// Specify row percentages
tCtl.rowPercent = 1;

// Tabulate
call tabulate(product_data, "Product_Type ~ Region", tCtl);</code></pre>
<pre>=====================================================================================
   Product_Type                               Region                            Total
=====================================================================================
                       East          North          South           West

       Clothing        12.5           62.5           12.5           12.5          100
    Electronics        38.5            7.7           38.5           15.4          100
      Furniture        30.0           30.0           10.0           30.0          100
     Home Goods        14.3           42.9           28.6           14.3          100
           Toys        33.3           25.0           16.7           25.0           99

=====================================================================================
Table reports row percentages.</pre>
<p>Alternatively we can find the column percentages:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Relative column tabulations
*/ 
struct tabControl tCtl;
tCtl = tabControlCreate();

// Compute row percentages
tCtl.columnPercent = 1;

// Tabulate product types
call tabulate(product_data, "Product_Type ~ Region", tCtl);</code></pre>
<pre>===========================================================================
   Product_Type                                  Region<br />
===========================================================================
                          East          North          South           West

       Clothing            7.1           33.3            9.1           10.0
    Electronics           35.7            6.7           45.5           20.0
      Furniture           21.4           20.0            9.1           30.0
     Home Goods            7.1           20.0           18.2           10.0
           Toys           28.6           20.0           18.2           30.0
          Total            100            100            100            100

===========================================================================
Table reports column percentages.</pre>
<h2 id="visualizing-distributions">Visualizing Distributions</h2>
<p>While tables provide numerical insights, frequency plots offer an intuitive visual representation. GAUSS 25 enhancements to the <code>plotFreq</code> function include:</p>
<ul>
<li><strong>Automatic category</strong> labeling for better clarity.</li>
<li><strong>New support</strong> for the <code>by</code> keyword to split data by category.</li>
<li><strong>New percentage distributions</strong>.</li>
</ul>
<h3 id="example-visualizing-product-type-percent-distribution">Example: Visualizing Product Type Percent Distribution</h3>
<p>To start, let's look at the percentage distribution of product type. To help with interpretation, we'll sort the graph by frequency and use a percentage axis:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Sort frequencies
sort = 1;

// Report percentage axis
pct_axis = 1;

// Generate frequency plot
plotFreq(product_data, "Product_Type", sort, pct_axis);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/03/product-percentage-distribution.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/03/product-percentage-distribution.jpg" alt="Product type percentage distribution plot in GAUSS." width="800" height="600" class="aligncenter size-full wp-image-11585168" /></a></p>
<h3 id="example-visualizing-product-type-distribution-by-region">Example: Visualizing Product Type Distribution by Region</h3>
<p>Next, let's visualize the distribution of the product types across regions using the <code>plotFreq</code> function and the <code>by</code> keyword:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Generate frequency plot
plotFreq(product_data, "Product_Type + by(Region)");</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/03/product-distribution-plot.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/03/product-distribution-plot.jpg" alt="Product distribution frequency plot. " width="800" height="600" class="aligncenter size-full wp-image-11585165" /></a> </p>
<h2 id="conclusion">Conclusion</h2>
<p>In this blog, we've demonstrated how updates to <code>frequency</code>, <code>tabulate</code>, and <code>plotFreq</code> in GAUSS 25 make categorical data analysis more efficient and insightful. These enhancements provide better readability, enhanced cross-tabulations, and more intuitive visualization options.</p>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/introduction-to-categorical-variables/" target="_blank" rel="noopener">Introduction to Categorical Variables</a>.</li>
<li><a href="https://www.aptech.com/blog/easy-management-of-categorical-variables/" target="_blank" rel="noopener">Easy Management of Categorical Variables</a></li>
<li><a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">What is a GAUSS Dataframe and Why Should You Care?</a>.</li>
<li><a href="https://www.aptech.com/blog/getting-started-with-survey-data-in-gauss/" target="_blank" rel="noopener">Getting Started With Survey Data In GAUSS</a>.</li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/exploring-categorical-data-in-gauss-25/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Making Your GAUSS Plots More Informative: Working with Legends</title>
		<link>https://www.aptech.com/blog/making-your-gauss-plots-more-informative-working-with-legends/</link>
					<comments>https://www.aptech.com/blog/making-your-gauss-plots-more-informative-working-with-legends/#comments</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Tue, 25 Feb 2025 00:26:24 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11585100</guid>

					<description><![CDATA[In data analysis, a well-designed graph can help clarify your insights but a poorly annotated one can confuse and distract your audience. That’s why proper annotation, including legends, is essential to creating effective graphs.

Legends play a crucial role in making graphs more readable by distinguishing between different groups, categories, or data series. A well-placed legend helps ensure that your message comes across clearly.

In this blog, we'll walk through how to add and customize legends in GAUSS graphics.]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>In data analysis, a well-designed graph can help clarify your insights but a poorly annotated one can confuse and distract your audience. That’s why proper annotation, including legends, is essential to creating effective graphs.</p>
<p>Legends play a crucial role in making graphs more readable by distinguishing between different groups, categories, or data series. A well-placed legend helps ensure that your message comes across clearly.</p>
<p>In this blog, we'll walk through how to add and customize legends in GAUSS graphics, covering:</p>
<ul>
<li>Adding a basic legend using <a href="https://docs.aptech.com/gauss/plotsetlegend.html" target="_blank" rel="noopener"><code>plotsetlegend</code></a>.</li>
<li>Customizing legend appearance with <a href="https://docs.aptech.com/gauss/plotsetlegendfont.html" target="_blank" rel="noopener"><code>plotsetlegendfont</code></a>, <a href="https://docs.aptech.com/gauss/plotsetlegendbkd.html" target="_blank" rel="noopener"><code>plotsetlegendbkd</code></a>, <a href="https://docs.aptech.com/gauss/plotsetlegendborder.html" target="_blank" rel="noopener"><code>plotsetlegendborder</code></a>, and <a href="https://docs.aptech.com/gauss/plotsetlegendtitle.html" target="_blank" rel="noopener"><code>plotsetlegendtitle</code></a>.</li>
<li>Understanding automatic legend creation when using the <code>by</code> keyword in formula strings.</li>
</ul>
<h2 id="automatically-adding-legends-with-the-by-keyword">Automatically Adding Legends with the <code>by</code> Keyword</h2>
<p>When using a <a href="https://www.aptech.com/resources/tutorials/formula-string-syntax/" target="_blank" rel="noopener">formula string</a> with the <code>by</code> keyword, GAUSS automatically generates a legend based on the <a href="https://www.aptech.com/blog/easy-management-of-categorical-variables/" target="_blank" rel="noopener">categorical variable</a>.</p>
<p>For example, let's create a scatter plot using the built-in <code>crabs.dta</code> dataset:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load data
fname = getGAUSSHome("examples/crabs.dta");
crabs = loadd(fname);

// Create scatter plot with automatic legend
plotScatter(crabs, "rear_width ~ body_depth + by(sex)");</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/02/crabs-scatter-by-sex-400x300px.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/02/crabs-scatter-by-sex-400x300px.jpg" alt="" width="400" height="300" class="aligncenter size-full wp-image-11585111" /></a></p>
<p>When the <code>by</code> keyword is used with the categorical variable, <code>sex</code> GAUSS:</p>
<ul>
<li>Plots a separate color for each group. </li>
<li>Automatically creates a legend indicating different groups.</li>
<li>Includes a title on the legend.</li>
</ul>
<p>These legends are useful when we just need a quick glance at our data. However, they don't allow for custom formatting. To use custom formatting we need to use a <code>plotControl</code> structure. </p>
<h2 id="setting-up-a-plotcontrol-structure">Setting Up a <code>plotControl</code> Structure</h2>
<p>To <a href="https://www.aptech.com/resources/tutorials/basic-graph-with-programmatic-customization/" target="_blank" rel="noopener">customize</a> a GAUSS <a href="https://www.aptech.com/resources/tutorials/introduction-to-gauss-graphing-data/" target="_blank" rel="noopener">plot</a>, the first step is to declare and initialize a <code>plotControl</code> structure. This structure is used for all plot-related settings, including axis labels, colors, fonts, legends, and more.</p>
<h3 id="why-use-a-plotcontrol-structure">Why Use a <code>plotControl</code> Structure?</h3>
<p>The <code>plotControl</code> structure provides a flexible and organized way to modify a plot’s appearance. Instead of manually formatting the plot after it is created, we can programmatically set all customizations in advance. This saves us time and effort when we need to reproduce our graphs.</p>
<p>To use this structure we:</p>
<ol>
<li>Declare a <code>plotControl</code> structure.</li>
<li>Fill it with default settings using <a href="https://docs.aptech.com/gauss/plotgetdefaults.html" target="_blank" rel="noopener">plotGetDefaults</a>.</li>
<li>Modify the structure’s properties as needed.</li>
<li>Pass the structure when calling our GAUSS plotting function.</li>
</ol>
<h3 id="declaring-and-initializing-the-plotcontrol-structure">Declaring and Initializing the <code>plotControl</code> Structure</h3>
<p>Every plot customization starts with the following setup:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare plot control structure
struct plotControl myPlot;

// Fill with default settings for an XY plot
myPlot = plotGetDefaults("xy");</code></pre>
<p>Notice that the defaults are specific to the plot type we are making. For example, if we were creating a bar or scatter plot, we would use &quot;bar&quot; or &quot;scatter&quot; instead.</p>
<p>Once the <code>plotControl</code> structure is initialized, we can customize all graph properties—such as adding a legend.</p>
<h2 id="adding-a-basic-legend">Adding a Basic Legend</h2>
<p>After declaring and initializing our <code>plotControl</code> structure, we can use the <code>plotSetLegend</code> function to add a default styled legend to any plot. </p>
<p>The function takes two required inputs: </p>
<ol>
<li>A pointer to a plot control structure.</li>
<li>A string array containing legend labels.</li>
</ol>
<p>Additionally, two optional arguments may be used:</p>
<ol>
<li>A string specifying the legend location. </li>
<li>A scalar indicating vertical or horizontal orientation.</li>
</ol>
<h3 id="adding-a-default-legend">Adding a Default Legend</h3>
<p>Let's look at adding a simple legend to an XY plot with the default location and orientation: </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare plot control structure
struct plotControl myPlot;

// Fill with default settings for xy plot
myPlot = plotGetDefaults("xy");

// Sample data
x = seqa(1, 1, 10);
y1 = x + rndn(10, 1);
y2 = x - 0.5 + rndn(10, 1);

// Specify legend labels
// using '$|" to concatenate 
// individual labels
label = "Group 1"$|"Group 2";

// Set up basic legend
plotSetLegend(&amp;myPlot, label);

// Create XY plot
plotXY(myPlot, x, y1~y2);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend-1-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend-1-1.jpg" alt="Default legend in GAUSS." width="600" height="400" class="aligncenter size-full wp-image-11585117" /></a></p>
<h3 id="changing-the-legend-location">Changing the Legend Location</h3>
<p>By default our legend is in the top, right corner of our plot canvas. This may not always be the ideal location, as we can see in the plot above. </p>
<p>Fortunately, the <em>location</em> input allows us to specify a different location. The <em>location</em> input can either be the xy coordinates for the top left of the legend, or a string. Setting xy coordinates allows for precise placement, but can sometimes be more cumbersome.</p>
<p>When specifying the legend location using a string, you may use one or more of the following:</p>
<ol>
<li>Vertical location: <code>"top"</code>(default), <code>"vcenter"</code>, or <code>"bottom"</code>.</li>
<li>Horizontal location: <code>"left"</code>, <code>"hcenter"</code>, or <code>"right"</code>(default).</li>
<li>Inside/outside location: <code>"inside"</code>(default) or <code>"outside"</code></li>
</ol>
<p>For example, let's change the legend location to the bottom, right corner of the plot:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Specify legend labels
// using '$|" to concatenate 
// individual labels
label = "Group 1"$|"Group 2";

// Place in bottom right corner
location = "bottom right";

// Set legend
plotSetLegend(&amp;myPlot, label, location);

// Create XY plot
plotXY(myPlot, x, y1~y2);</code></pre>
<p>These location components can be specified in any order. For example, we would get the same results specifying the location like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Place in bottom right corner
location = "right bottom";</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend-2-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend-2-1.jpg" alt="Changing the location of a GAUSS legend. " width="600" height="400" class="aligncenter size-full wp-image-11585118" /></a></p>
<p>We could create a very similar graph by specifying the top left of the legend to be at <code>x=7.5</code> and <code>y=2</code> like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Specify xy coordinates for the top left corner of the legend.
location = { 7.5, 2 };</code></pre>
<h3 id="changing-the-legend-orientation">Changing the Legend Orientation</h3>
<p>The <code>plotSetLegend</code> procedure also allows us to specify if the series are listed horizontally or vertically using the optional <em>orientation</em> input. </p>
<p>The orientation input is set to:</p>
<ol>
<li>1 for a vertical series list (default). </li>
<li>0 for a horizontal series list. </li>
</ol>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Specify legend labels
// using '$|" to concatenate 
// individual labels
label = "Group 1"$|"Group 2";

// Place in bottom right corner
location = "bottom right";

// Set to horizontal list
orientation = 0;

// Set legend
plotSetLegend(&amp;myPlot, label, location, orientation);

// Create XY plot
plotXY(myPlot, x, y1~y2);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend3.png"><img src="https://www.aptech.com/wp-content/uploads/2025/02/basic-legend3.png" alt="Changing the orientation of a GAUSS legend. " width="600" height="400" class="aligncenter size-full wp-image-11585119" /></a></p>
<h2 id="advanced-legend-formatting">Advanced Legend Formatting</h2>
<p>In addition to the basic legend, GAUSS provides several functions to customize legend appearance.</p>
<table>
  <thead>
    <tr>
      <th colspan="3">
        <h3 id="gauss-legend-customization-functions"><br>GAUSS Legend Customization Functions</h3>
      </th>
    </tr>
    <tr>
      <th>Function Name</th>
      <th>Description</th>
      <th>Example</th>
    </tr>
  </thead>
  <tbody>
     <tr>
      <td><a href="https://docs.aptech.com/gauss/plotsetlegend.html" target="_blank" rel="noopener">plotSetLegend</a></td>
      <td>Defines a legend for the plot with custom labels.</td>
      <td><code>plotSetLegend(&amp;myPlot, label [, location, orientation]);</code></td>
    </tr>
     <tr>
      <td><a href="https://docs.aptech.com/gauss/plotsetlegendbkd.html" target="_blank" rel="noopener">plotSetLegendBkd</a></td>
      <td>Sets the opacity and color for the background of a graph legend.</td>
      <td><code>plotSetLegendBkd(&amp;myPlot, opacity [, bkd_clr]);</code></td>
    </tr>
    <tr>
      <td><a href="https://docs.aptech.com/gauss/plotsetlegendborder.html" target="_blank" rel="noopener">plotSetLegendBorder</a></td>
      <td>Controls the color and thickness of the legend border.</td>
      <td><code>plotSetLegendBorder(&amp;myPlot, clr [, thickness]);</code></td>
    </tr>
    <tr>
      <td><a href="https://docs.aptech.com/gauss/plotsetlegendfont.html" target="_blank" rel="noopener">plotSetLegendFont</a></td>
      <td>Customizes the font style, size, and color of legend text.</td>
      <td><code>plotSetLegendFont(&amp;myPlot, font [, font_size, font_color]);</code></td>
    </tr>
<tr>
      <td><a href="https://docs.aptech.com/gauss/plotsettextinterpreter.html" target="_blank" rel="noopener">plotSetLegendTitle</a></td>
      <td>Controls the legend title.</td>
      <td><code>plotSetLegendTitle(&amp;myPlot, title)</code></td>
    </tr>
    <tr>
      <td><a href="https://docs.aptech.com/gauss/plotsettextinterpreter.html" target="_blank" rel="noopener">plotSetTextInterpreter</a></td>
      <td>Controls the text interpreter settings for a graph.</td>
      <td><code>plotSetTextInterpreter(&amp;myPlot, interpreter [, location]);</code></td>
    </tr>
  </tbody>
</table>
<h3 id="example-advanced-legend-formatting">Example: Advanced Legend Formatting</h3>
<p>Let's look at another plotting example and explore some of the advanced legend formatting options. </p>
<p>To get started, we will simulate some data:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Create the sequence 0.25, 0.5, 0.75...3
*/
x = seqa(0.25, 0.25, 12);
y = sin(x);</code></pre>
<p>and setup our <code>plotControl</code> structure</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare plotControl structure
// and fill with default settings for XY plots
struct plotControl myPlot;
myPlot = plotGetDefaults("xy");</code></pre>
<p>We want the legend for this plot to:</p>
<ol>
<li>Be horizontally centered and placed outside the bottom of the plot.</li>
<li>Use 14 pt., &quot;dark blue&quot;, Arial font.</li>
<li>Have a &quot;light gray&quot; border with a thickness of 2 pixels.</li>
<li>Render and interpret labels using latex. </li>
</ol>
<h4 id="labels-and-location">Labels and Location</h4>
<p>We set the labels and location using the <code>plotSetLegend</code> procedure:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Basic legend settings
*/
// Set label
label = "\sin{x}";

// Set location
location = "bottom hcenter outside";

// Set legend 
plotSetLegend(&amp;myPlot, label, location);</code></pre>
<h4 id="legend-font-properties">Legend Font Properties</h4>
<p>The <code>plotSetLegendFont</code> function allows us to adjust the font style, size, and color of the legend text.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Legend font
*/
// Set font
font_style = "Arial";

// Set font size
font_size = 14;

// Set font color
font_clr = "dark blue";

// Set all legend font properties
plotSetLegendFont(&amp;myPlot, font_style, font_size, font_clr);</code></pre>
<h4 id="customizing-the-legend-border">Customizing The Legend Border</h4>
<p>The <code>plotSetLegendBorder</code> procedure sets the color and width of the border. </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Legend border
*/

// Set border color
border_clr = "light gray";

// Border width
border_width = 2;

// Set the legend border 
plotSetLegendBorder(&amp;myPlot, border_clr, border_width);</code></pre>
<h4 id="changing-text-interpretation">Changing Text Interpretation</h4>
<p>By default, GAUSS treats legend text as plain text. However, we can enable LaTeX-style formatting using <code>plotSetTextInterpreter</code>:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Set text interpret to interpret
** latex for legend labels
*/
plotSetTextInterpreter(&amp;myPlot, "latex", "legend");</code></pre>
<h4 id="generating-our-plot">Generating Our Plot</h4>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create XY plot
plotXY(myPlot, x, y);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2025/02/advanced-legend-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2025/02/advanced-legend-1.jpg" alt="Advanced legend formatting in GAUSS. " width="600" height="400" class="aligncenter size-full wp-image-11585121" /></a></p>
<h2 id="conclusion">Conclusion</h2>
<p>In this blog, we covered different ways to customize legends in GAUSS plots:</p>
<ul>
<li>Adding a legend using <code>plotSetLegend</code>.</li>
<li>Modifying fonts, backgrounds, and borders for better visualization.</li>
<li>Utilizing LaTeX formatting and adding legend titles.</li>
<li>Automatically generating legends using the <code>by</code> keyword.</li>
</ul>
<p>These techniques enhance the clarity of your visualizations, making it easier to interpret results.</p>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/" target="_blank" rel="noopener">How to mix, match and style different graph types</a></li>
<li><a href="https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/" target="_blank" rel="noopener">How to Interactively Create Reusable Graphics Profiles</a></li>
<li><a href="https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/" target="_blank" rel="noopener">How to Create Tiled Graphs in GAUSS</a></li>
<li><a href="https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/" target="_blank" rel="noopener">Visualizing COVID-19 Panel Data With GAUSS 22</a></li>
<li><a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/" target="_blank" rel="noopener">Advanced Formatting Techniques for Creating AER Quality Plots</a></li>
<li><a href="https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/" target="_blank" rel="noopener">Introduction to Efficient Creation of Detailed Plots</a></li>
</ol>
<p></p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/making-your-gauss-plots-more-informative-working-with-legends/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Introduction to Efficient Creation of Detailed Plots</title>
		<link>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/</link>
					<comments>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 27 Sep 2022 16:26:33 +0000</pubDate>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11582941</guid>

					<description><![CDATA[A few weeks ago, we showed you how to create a detailed plot from a recent article in the American Economic Review. That article contained several plots that contain quite a bit of similar and stylized formatting. Today we will show you how to <i>efficiently</i> create two of these graphs.

Our main goals are to get you thinking about code reuse and how it can help you:

<ul>
<li> Get more results from your limited research time.</li>
<li>Avoid the frustration that comes from growing mountains of spaghetti code.</li>
</ul>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>A few weeks ago, we showed you how to create a detailed plot from a recent article in the American Economic Review. That article contained several plots that contain quite a bit of similar and stylized formatting. Today we will show you how to <em>efficiently</em> create two of these graphs.</p>
<p>Our main goals are to get you thinking about code reuse and how it can help you:</p>
<ul>
<li>Get more results from your limited research time.</li>
<li>Avoid the frustration that comes from growing mountains of spaghetti code.</li>
</ul>
<div class="alert alert-info" role="alert">If you missed it, be sure to check out our original blog on this topic, <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/" target="_blank" rel="noopener">Advanced Formatting Techniques for Creating AER Quality Plots</a>. </div>
<h2 id="our-graphs">Our Graphs</h2>
<p>This is what we will create today. As you can see they share many style attributes. This gives us a great opportunity to reuse code.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/09/gblog-hetboombust1x2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/09/gblog-hetboombust1x2.jpg" alt="Line plots from an American Economic Review article created by GAUSS." width="1000" height="400" class="aligncenter size-full wp-image-11582942" /></a></p>
<p>You can <a href="https://raw.githubusercontent.com/aptech/gauss_blog/master/programming/introduction-efficient-creation-plots-9.27.22/rationing.csv" target="_blank" rel="noopener">download the data here</a>. </p>
<h2 id="our-initial-code">Our Initial Code</h2>
<p>This is not a massive amount of code and many of you might be tempted to just copy and paste this code and make the minor modifications needed to get your desired result. I completely understand. Your biggest problem is probably a lack of time, so productivity is paramount.</p>
<p>While it might feel like this is a shortcut, it will saddle you with technical debt. Technical debt is just a fancy term that describes the stress, frustration, and time-wasting that inevitably occurs when you take shortcuts like this.</p>
<p>Not only will this save you pain, but it might save you some embarrassment as well. These sorts of mundane issues are real drivers of the replication crises in research today.</p>
<p>Your research is important and I know you want to do it right, so let's get started! </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Default settings
struct plotControl plt;
plt = plotGetDefaults("xy");

// Font
plotSetFonts(&amp;plt, "all", "roboto", 14);

// Legend
plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);

// Main line settings
clrs = getColorPalette("set2");
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

// Axes outline (spine)
plotSetOutlineEnabled(&amp;plt, 1);

// X-axis
plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

// Y-axis
plotSetYLabel(&amp;plt, "interest rate");

// Draw main plot
plotXY(plt, int_rate, "high + low ~ x");

// Style and add vertical lines
plotSetLinePen(&amp;plt, 1, "#CCC", 2);
plotAddVLine(plt, ks);

// Style text boxes
struct plotAnnotation ant;
ant = annotationGetDefaults();
annotationSetTextInterpreter(&amp;ant, "latex");
annotationSetLinePen(&amp;ant, 0, "", -1);
annotationSetFont(&amp;ant, "", 14, "#3333");
annotationSetBkd(&amp;ant, "", 0);

// Add text boxes
plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="initial-code-simplification">Initial Code Simplification</h2>
<p>We will start by creating a <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/" target="_blank" rel="noopener">procedure</a> to hold some of the plot styling functions that we want to repeat and apply them to the first plot only. Then we will add the data for the second plot.</p>
<p>It looks like all of the styling applied before the call to <a href="https://docs.aptech.com/gauss/plotxy.html" target="_blank" rel="noopener"><code>plotXY</code></a> will be the same in both plots, but the y-axis label text is different. So, let's create a procedure that will apply the main settings:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Declare plotControl structure
struct plotControl plt;

// Fill with defaults for this project
plt = pltDefaults();

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "interest rate");

// Draw first plot
plotXY(plt, int_rate, "high + low ~ x");

proc (1) = pltDefaults();
    local clrs;

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Font
    plotSetFonts(&amp;plt, "all", "roboto", 14);

    // Legend
    plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
    plotSetLegendBkd(&amp;plt, 0);

    // Main line settings
    clrs = getColorPalette("set2");
    plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

    // Axes outline (spine)
    plotSetOutlineEnabled(&amp;plt, 1);

    // X-axis
    plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
    plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

    retp(plt);
endp;
</code></pre>
<p>While this code is slightly longer when drawing just one plot, it will save us when we add the next plot. Before we do that, we need to address the <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#add-vertical-lines" target="_blank" rel="noopener">vertical lines</a> and <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#add-text-annotations" target="_blank" rel="noopener">annotations</a>.</p>
<h2 id="simplifying-the-annotations">Simplifying the Annotations</h2>
<p>Looking over the plots at the top of this article shows us that the vertical lines and the omega text boxes all depend on the <code>ks</code> vector. Since they seem to be intertwined, it is probably safe to put them in one procedure. </p>
<p>The simplest thing to do would be to add all the annotation code to a single procedure like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    // Style text boxes
    struct plotAnnotation ant;
    ant = annotationGetDefaults();
    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<p>and then call that procedure right after <code>plotXY</code>. In this case, it is not a bad place to start. However, since we are in learning mode, let's pretend that we were going to create more graphs in this file that would add text boxes with the same styling, but would use different greek letters and would be located in a different place in the graph.</p>
<p>In that case, we would probably want to separate the text box styling from the text box drawing, like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (1) = textBoxDefaults();
    struct plotAnnotation ant;
    ant = annotationGetDefaults();

    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    retp(ant);
endp;

proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    struct plotAnnotation ant;
    ant = textBoxDefaults();

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<h3 id="conclusion-and-final-code">Conclusion and final code</h3>
<p>Below is the final code to create the graphs from the top of this blog. This isn't designed to show you the best way to write this code, but rather to get you started with the idea of code reuse.</p>
<p>Software engineers sometimes use the acronym DRY — Don't Repeat Yourself. While that is a great practice, even just repeating yourself less often will bring you great rewards.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");
tail(int_rate);

rationing = loadd("rationing.csv");
tail(rationing);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 1000 | 400);

// Declare plotControl structure and
// fill with defaults for this project
struct plotControl plt;
plt = pltDefaults();

/*
** Interest rate plot
*/

// Create grid for multiple plots
plotLayout(1,2,1);

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "interest rate");

// Draw first plot
plotXY(plt, int_rate, "high + low ~ x");
pltAddOmegas(ks);

/*
** Rationing plot
*/

// Create grid for multiple plots
plotLayout(1,2,2);

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "rationing");

// Draw first plot
plotXY(plt, rationing, "high + low ~ x");
pltAddOmegas(ks);

proc (1) = pltDefaults();
    local clrs;

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Font
    plotSetFonts(&amp;plt, "all", "roboto", 14);

    // Legend
    plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
    plotSetLegendBkd(&amp;plt, 0);

    // Main line settings
    clrs = getColorPalette("set2");
    plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

    // Axes outline (spine)
    plotSetOutlineEnabled(&amp;plt, 1);

    // X-axis
    plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
    plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

    retp(plt);
endp;

proc (1) = textBoxDefaults();
    struct plotAnnotation ant;
    ant = annotationGetDefaults();

    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    retp(ant);
endp;

proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    struct plotAnnotation ant;
    ant = textBoxDefaults();

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/" target="_blank" rel="noopener">Advanced Formatting Techniques for Creating AER Quality Plots.</a></li>
<li><a href="https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/" target="_blank" rel="noopener">Visualizing COVID-19 Panel Data With GAUSS 22.</a> </li>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/" target="_blank" rel="noopener">How to Mix, Match and Style Different Graph Types.</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Advanced Formatting Techniques for Creating AER Quality Plots</title>
		<link>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/</link>
					<comments>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#comments</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Wed, 27 Jul 2022 21:18:24 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11582603</guid>

					<description><![CDATA[This blog will show you how to reproduce one of the graphs from a paper in the June 2022 issue of the American Economic Review. You will learn how to:
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li> Set the font for all or a subset of the graph text elements.</li>
<li> Set the size of your graph.</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today's blog will show you how to reproduce one of the graphs from a paper in the June 2022 issue of the journal, <a href="https://www.aeaweb.org/journals/aer" target="_blank" rel="noopener">American Economic Review</a>. You will learn how to:</p>
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li>Set the font for all or a subset of the graph text elements.</li>
<li>Set the size of your graph.</li>
</ol>
<h2 id="the-graph-and-data">The Graph and Data</h2>
<p>Below is the graph that we are going to create. It is adapted from a recent paper in the American Economic Review. You can <a href="https://raw.githubusercontent.com/aptech/gauss_blog/master/graphics/advanced-formatting-aer-quality/int_rate.csv" target="_blank" rel="noopener">download the data here</a>.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-final.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-final.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582641" /></a></p>
<h2 id="load-and-preview-data">Load and Preview Data</h2>
<p>Our first step will be to <a href="https://www.aptech.com/resources/tutorials/loading-variables-from-a-file/" target="_blank" rel="noopener">load the data</a> and take a quick look at it.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load all variables from 'int_rate.csv'
int_rate = loadd("int_rate.csv");

// Print the first 5 observations of 'int_rate'
print "First 5 observations:";
head(int_rate);

// Print the last 5 observations of 'int_rate'
print "Last 5 observations:";
tail(int_rate);

// Print descriptive statistics of our variables
call dstatmt(int_rate);</code></pre>
<p>This will give us the following results:</p>
<pre>First 5 observations:

               x             high              low
   0.00010000000       0.17140598        0.0000000
   0.00020000000       0.17140598        0.0000000
   0.00030000000       0.17140598        0.0000000
   0.00040000000       0.17140598        0.0000000
   0.00050000000       0.17140598        0.0000000

Last 5 observations:

               x             high              low
      0.99950000       0.17140598       0.23012203
      0.99960000       0.17140598       0.23012203
      0.99970000       0.17140598       0.23012203
      0.99980000       0.17140598       0.23012203
      0.99990000       0.17140598       0.23012203

-------------------------------------------------------------------------------
Variable     Mean    Std Dev     Variance    Minimum    Maximum   Valid Missing
-------------------------------------------------------------------------------

x             0.5      0.289       0.0833      1e-4      0.999    9999    0
high       0.1714   1.04e-07     1.08e-14     0.171      0.171    9999    0
low       0.09374      0.108       0.0116         0      0.230    9999    0</pre>
<h2 id="initial-graphs">Initial Graphs</h2>
<p>Our first graphs will use the default GAUSS styling. We will create one graph indexing our <code>x</code> and <code>y</code> variables and another using a <a href="https://www.aptech.com/resources/tutorials/formula-string-syntax/" target="_blank" rel="noopener">formula string</a>.</p>
<h3 id="indexing">Indexing</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-index.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-index.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582627" /></a></p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set our graph size to 500x400 pixels
plotCanvasSize("px", 500 | 400);

// Use indexing to select the 'x' and 'y' variables
plotXY(int_rate[.,"x"], int_rate[.,"high" "low"]);</code></pre>
<h3 id="formula-string">Formula string</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-formula.png"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-formula.png" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582634" /></a></p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set our graph size to 500x400 pixels
plotCanvasSize("px", 500 | 400);

// Specify the 'x' and 'y' variables using a formula string
plotXY(int_rate, "high + low ~ x");</code></pre>
<p>When we use a formula string with our plot functions, it tells GAUSS that we want to use the information from the <a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">dataframe</a>.</p>
<p>When using a formula string in plots:</p>
<ul>
<li>The tilde symbol, <code>~</code>, separates the <code>y</code> variables on the left from the <code>x</code> variable(s) on the right. </li>
<li>If there is a single <code>y</code> variable, GAUSS will use that variable name to label the <code>y</code> axis. If there is more than one <code>y</code> variable, then the variable names will be added to the legend.</li>
<li>The name of the <code>x</code> variable will be used to label the x-axis.</li>
</ul>
<p>While this may not always be the information we want to be displayed in our final plot, it makes it convenient to quickly create graphs that are easier to interpret.</p>
<h2 id="plot-styling">Plot Styling</h2>
<p>Fp
Next, we will adjust the styling to match our intended final plot.</p>
<p>To programmatically style our graph, the first thing we need to do is to create a <code>plotControl</code> structure and fill it with default values.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">struct plotControl plt;
plt = plotGetDefault("xy");</code></pre>
<h3 id="legend-styling">Legend styling</h3>
<p>After the pointer to the <code>plotControl</code> structure we want to modify, <code>&amp;plt</code>, the function <a href="https://docs.aptech.com/gauss/plotsetlegend.html" target="_blank" rel="noopener"><code>plotSetLegend</code></a> takes one required input and two optional ones.</p>
<ol>
<li>
<p><strong>Legend text</strong>: This controls the text that will be displayed in the legend. We want GAUSS to use the variable names from our input. Therefore, below, we set this to an empty string, <code>""</code>. This tells GAUSS that we do not want to modify the default behavior of the legend text.</p>
<p>As we mentioned earlier, the default behavior for a graph created with a formula string with more than one <code>y</code> variable is to use the <code>y</code> variable names as the legend text elements.</p>
</li>
<li>
<p><strong>Legend location</strong>: This input can be a string with text location specifications, or a 2x1 vector with the <code>x</code> and <code>y</code> coordinates for the location of the top-left corner of the legend.</p>
</li>
<li><strong>Legend orientation</strong>: This input specifies whether the legend position should be stacked vertically or horizontally. We set it to <code>1</code> to indicate a vertical arrangement. It may help to remember that a <code>1</code> is a vertical essentially a vertical mark.</li>
</ol>
<p>The first input to <a href="https://docs.aptech.com/gauss/plotsetlegendbkd.html" target="_blank" rel="noopener"><code>plotSetLegendBkd</code></a>, after the <code>plotControl</code> structure pointer, controls the legend opacity. We set it to be 0% opaque, or 100% transparent.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);</code></pre>
<h3 id="font-styling">Font styling</h3>
<p><a href="https://docs.aptech.com/gauss/plotsetfonts.html" target="_blank" rel="noopener"><code>plotSetFonts</code></a> provides a convenient way to set the font family, size, and color for any subset of the text in your graph. Below we set the font for 'all' of the text in the plot. However, there are many other options, including: <code>"axes"</code>, <code>"legend"</code>, <code>"legend_title"</code>, <code>"title"</code>, <code>"ticks"</code> and many more.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetFonts(&amp;plt, "all", "roboto", 14);</code></pre>
<h3 id="x-axis-label">X-axis label</h3>
<p><a href="https://docs.aptech.com/gauss/plotsettextinterpreter.html" target="_blank" rel="noopener"><code>plotSetTextInterpreter</code></a> tells GAUSS whether you would like text labels to be interpreted as:</p>
<ul>
<li>HTML</li>
<li>LaTeX</li>
<li>Plain text</li>
</ul>
<p>Like <code>plotSetFonts</code>, it allows you to specify many different locations, or even, <code>"all"</code>. Below, we set the x-axis to be interpreted as LaTeX and then use LaTeX in our x-axis label.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");</code></pre>
<h3 id="main-line-styling">Main line styling</h3>
<p>The &quot;set2&quot; <a href="https://docs.aptech.com/gauss/getcolorpalette.html" target="_blank" rel="noopener">color palette</a> contains eight colors:<br/>
<span><svg height="24" width="192">    <rect fill="rgb(102,194,165)" width="24" height="24" x="0"></rect>    <rect fill="rgb(252,141,98)" width="24" height="24" x="24"></rect>    <rect fill="rgb(141,160,203)" width="24" height="24" x="48"></rect>    <rect fill="rgb(231,138,195)" width="24" height="24" x="72"></rect>    <rect fill="rgb(166,216,84)" width="24" height="24" x="96"></rect>    <rect fill="rgb(255,217,47)" width="24" height="24" x="120"></rect>    <rect fill="rgb(229,196,148)" width="24" height="24" x="144"></rect>    <rect fill="rgb(179,179,179)" width="24" height="24" x="168"></span></p>
<p>We want to use the third color for our first series, &quot;high&quot;, and the second color for our second series, &quot;low&quot;.</p>
<p>Additionally, we set the line width to <code>4</code> pixels and set the line style to <code>1</code> and <code>3</code> respectively. One indicates a solid line and three is for a dotted line.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">clrs = getColorPalette("set2");

// Set the line width, line colors, and line style
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);</code></pre>
<h3 id="axes-outline">Axes outline</h3>
<p>The axes outline, or spine as they are called by other libraries, controls the lines around the edges of the data area. By default, the bottom x-axis and left y-axis are enabled. The code below will also turn on the lines on the top x-axis and right y-axis.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetOutlineEnabled(&amp;plt, 1);</code></pre>
<h3 id="graph-before-annotations">Graph before annotations</h3>
<p>If we draw the graph, using our previous styling and a formula string as shown below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotXY(plt, int_rate, "high + low ~ x");</code></pre>
<p>we get the following plot:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-styled-wo-annotations.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-styled-wo-annotations.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582659" /></a></p>
<h2 id="add-vertical-lines">Add Vertical Lines</h2>
<h3 id="line-styling">Line styling</h3>
<p>We will continue with the <code>plotControl</code> structure we created earlier and modify the line settings to match the vertical lines from the graph we are trying to reproduce.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set lines to be: 1 pixel wide, light gray (#CCC) and dashed style (2)
plotSetLinePen(&amp;plt, 1, "#CCC", 2);</code></pre>
<h3 id="draw-the-lines">Draw the lines</h3>
<p>We add the vertical lines using <a href="https://docs.aptech.com/gauss/plotaddvline.html" target="_blank" rel="noopener"><code>plotAddVLine</code></a>. <code>plotAddVLine</code> takes an optional <code>plotControl</code> structure as the first input and then a vector of one or more x-axis locations at which to draw the vertical spanning lines.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// The x-axis locations for the vertical lines
ks = { 0.517, 0.653, 0.781 };

plotAddVLine(plt, ks);</code></pre>
<h2 id="add-text-annotations">Add Text Annotations</h2>
<h3 id="style-text-boxes">Style text boxes</h3>
<p>The annotation styling functions use a <code>plotAnnotation</code> structure but work very similarly to the main plot styling (<code>plotSet</code>) functions. Therefore, we will just use comments to describe their actions.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">struct plotAnnotation ant;
ant = annotationGetDefaults();

// Set text to be interpreted as LaTeX
annotationSetTextInterpreter(&amp;ant, "latex");

// Turn off the text box bounding line, by setting:
//     line-width=0, line-color="" (ignore), line-style=-1 (no line)
annotationSetLinePen(&amp;ant, 0, "", -1);

// Leave the font-family as default, "",
// Set the font-size to 14 points and the color to a
// dark gray, #333
annotationSetFont(&amp;ant, "", 14, "#3333");

// Leave the annotation background color, "".
// Set the opacity to 0% (100% transparent)
annotationSetBkd(&amp;ant, "", 0);</code></pre>
<h3 id="draw-the-text-boxes">Draw the text boxes</h3>
<p>After the optional <code>plotAnnotation</code> structure, <a href="https://docs.aptech.com/gauss/plotaddtextbox.html" target="_blank" rel="noopener"><code>plotAddTextbox</code></a> takes 3 input arguments:</p>
<ol>
<li><strong>The text to display.</strong><br/></li>
<li><strong>The x-axis coordinate.</strong><br/></li>
<li><strong>The y-axis coordinate.</strong><br/></li>
</ol>
<p>By default, the x and y-axis coordinates specify the location of the top-left of the bounding box that contains the text.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="full-code">Full code</h2>
<p>Below is the full code to create our graph.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Default settings
struct plotControl plt;
plt = plotGetDefaults("xy");

// Font
plotSetFonts(&amp;plt, "all", "roboto", 14);

// Legend
plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);

// Main line settings
clrs = getColorPalette("set2");
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

// Axes outline (spine)
plotSetOutlineEnabled(&amp;plt, 1);

// X-axis
plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

// Draw main plot
plotXY(plt, int_rate, "high + low ~ x");

// Style and add vertical lines
plotSetLinePen(&amp;plt, 1, "#CCC", 2);
plotAddVLine(plt, ks);

// Style text boxes
struct plotAnnotation ant;
ant = annotationGetDefaults();
annotationSetTextInterpreter(&amp;ant, "latex");
annotationSetLinePen(&amp;ant, 0, "", -1);
annotationSetFont(&amp;ant, "", 14, "#3333");
annotationSetBkd(&amp;ant, "", 0);

// Add text boxes
plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="bonus-content-text-box-anchor-position">Bonus Content: Text Box Anchor Position</h2>
<p>For this case, we wanted the text boxes to appear to just the right of the vertical lines and the vertical position of the text boxes was not critical. Therefore, the default anchor position worked well.</p>
<p>However, if we had needed the text boxes to be towards the bottom of the graph, the first of them would have overlapped with one of our lines. We can see this by changing the <code>plotAddTextbox</code> lines to the following:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Draw the text boxes at a lower position, y=0.04
plotAddTextbox(ant, "\\omega_1", ks[1], 0.04);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.04);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.04);</code></pre>
<p>This makes the bottom of our graph look like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-overlapping-omega-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-overlapping-omega-1.jpg" alt="" width="499" height="145" class="aligncenter size-full wp-image-11582674" /></a></p>
<p>In this case, it would be nice to move the text boxes to the left of the vertical line. We can do this by using the final optional input of <code>plotAddTextbox</code>. It is a string that allows you to specify the position of the text box with respect to its anchor position.</p>
<p>The string options include:</p>
<ul>
<li><strong>Vertical position</strong>: <code>"top"</code>, <code>"vcenter"</code>, <code>"bottom"</code>.<br/></li>
<li><strong>Horizontal position</strong>: <code>"left"</code>, <code>"hcenter"</code>, <code>"right"</code>.<br/></li>
</ul>
<p>or <code>"center"</code> which is equivalent to <code>"vcenter hcenter"</code>.</p>
<p>For this example, we will just move the text boxes to the left of the vertical lines which are at the same position as the text box's anchor locations:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Draw the text boxes at a lower position, y=0.04
plotAddTextbox(ant, "\\omega_1", ks[1], 0.04, "left");
plotAddTextbox(ant, "\\omega_2", ks[2], 0.04, "left");
plotAddTextbox(ant, "\\omega_3", ks[3], 0.04, "left");</code></pre>
<p>This gives us the following image:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-left-omega-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-left-omega-1.jpg" alt="" width="496" height="142" class="aligncenter size-full wp-image-11582676" /></a></p>
<h3 id="conclusion">Conclusion</h3>
<p>Great job! You have learned how to:</p>
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li>Set the font for all or a subset of the graph text elements.</li>
<li>Set the size of your graph.</li>
<li>Control the position of text boxes with respect to their attachment point.</li>
</ol>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/" target="_blank" rel="noopener">Visualizing COVID-19 Data with GAUSS 22</a></li>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/" target="_blank" rel="noopener">How to Mix, Match, and Style Different Graph Types</a></li>
<li><a href="https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/" target="_blank" rel="noopener">How to Create Tiled Graphs in GAUSS</a></li>
<li><a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/" target="_blank" rel="noopener">Five Hacks for Creating Custom GAUSS Graphics</a></li>
</ol>
<h3 id="references">References</h3>
<p>Farboodi, Maryam, and Péter Kondor. 2022. &quot;Heterogeneous Global Booms and Busts.&quot; <i>American Economic Review</i>, 112 (7): 2178-2212.
DOI: 10.1257/aer.20181830</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Visualizing COVID-19 Panel Data With GAUSS 22</title>
		<link>https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/</link>
					<comments>https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/#comments</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Tue, 14 Dec 2021 18:57:02 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Panel data]]></category>
		<category><![CDATA[#gauss22]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11582197</guid>

					<description><![CDATA[When they're done right, graphs are a useful tool for telling compelling data stories and supporting data models. However, too often graphs lack the right components to truly enhance understanding. 

In this blog, we look at how a few quick customizations help make graphs more impactful. In particular, we will consider:
<ul>
<li>Using grid lines without cluttering a graph. </li>
<li>Changing tick labels for readability. </li>
<li>Using clear axis labels. </li>
<li>Marking events and outcomes with lines, bars, and annotations. </li>
</ul>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>When they're done right, graphs are a useful tool for telling compelling data stories and supporting data models. However, too often graphs lack the right components to truly enhance understanding. </p>
<p>In this blog, we look at how a few quick customizations help make graphs more impactful. In particular, we will consider:</p>
<ul>
<li>Using grid lines without cluttering a graph. </li>
<li>Changing tick labels for readability. </li>
<li>Using clear axis labels. </li>
<li>Marking events and outcomes with lines, bars, and annotations. </li>
</ul>
<h2 id="data">Data</h2>
<p>As an example, we will use New York Times COVID tracking data <a href="https://github.com/nytimes/covid-19-data/tree/master/rolling-averages">(available on GitHub)</a>. This data is part of the <a href="https://www.nytimes.com/interactive/2020/us/coronavirus-us-cases.html">New York Times U.S. tracking project</a>. </p>
<p>From this data, we will be using the rolling 7-day average of COVID cases per 100k provided by date for five states: Arizona, California, Florida, Texas, and Washington. </p>
<h2 id="creating-a-basic-graph">Creating a Basic Graph</h2>
<p>Let's start by creating a basic panel data plot using:</p>
<ul>
<li>The <a href="https://docs.aptech.com/gauss/plotxy.html"><code>plotXY</code></a> procedure with dates. </li>
<li>A <a href="https://www.aptech.com/resources/tutorials/formula-string-syntax/">formula string</a> and the <code>by</code> keyword. </li>
</ul>
<p>First we will load our data: </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load original data
fname = "us_state_covid_cases.csv";
covid_cases = loadd(fname, 
                    "date($date) + cat(state) + cases + cases_avg_per_100k");

// Filter desired states
covid_cases = selif(covid_cases, 
                    rowcontains(covid_cases[., "state"], 
                                "Florida"$|"California"$|
                                "Arizona"$|"Washington"$|
                                "Texas"));</code></pre>
<p>Note that in this step we've:</p>
<ol>
<li>Specified the variables we want to load and their variable types.</li>
<li>Filtered our data to include only our states of interest. </li>
</ol>
<div class="alert alert-info" role="alert">For more information about loading data and other data management tips see our previous blog, <a href="https://www.aptech.com/blog/getting-to-know-your-data-with-gauss-22/">Getting to Know Your Data with GAUSS 22</a>.</div>
<p>Now, we can make a preliminary plot of the rolling 7 day average number of COVID-19 cases per 100,000 people:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Plot COVID cases per 100K by state
plotXY(covid_cases, "cases_avg_per_100k ~ date + by(state)");</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-basic.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-basic.jpg" alt="" width="753" height="566" class="alignnone size-full wp-image-11582241" /></a></p>
<div class="alert alert-info" role="alert">The <code>by</code> keyword tells GAUSS to split the data on a particular variable. It was introduced in GAUSS 22, as well as the capability to use <code>plotXY</code> with date variables.</div>
<h3 id="customizing-our-graph">Customizing Our Graph</h3>
<p>Our quick graph was a good starting point. However, a few customizations will help present a clearer picture:</p>
<ul>
<li>Adding y-axis grid lines will help us read COVID cases values more easily.</li>
<li>Reformatting our x-axis tick labels to include months rather than quarters will make the dates more recognizable. </li>
<li>Change axis labels. </li>
</ul>
<h3 id="declaring-a-plotcontrol-structure">Declaring a <code>plotControl</code> Structure</h3>
<p>The first step for customizing graphs is to declare a <code>plotControl</code> structure and to fill it with the appropriate defaults:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare plot control structure
struct plotControl myPlot;

// Fill with defaults for "xy" graph
myPlot = plotGetDefaults("xy");</code></pre>
<h3 id="customizing-plot-attributes">Customizing Plot Attributes</h3>
<p>After declaring the <code>plotControl</code> structure, we can use <code>plotSet</code> procedures to change the desired attributes of our graph. </p>
<h4 id="adding-y-axis-grid-lines">Adding Y-Axis Grid Lines</h4>
<p>First, to help make levels of COVID cases more clear, let's add y-axis grid lines to our plot using <a href="https://docs.aptech.com/gauss/plotsetygridpen.html"><code>plotSetYGridPen</code></a>.</p>
<p>The <code>plotSetYGridPen</code> procedure can be used to set the <em>width</em>, <em>color</em>, and <em>style</em> of the y-axis grid lines:</p>
<ul>
<li>Turn on y-axis major and/or minor grids.</li>
<li>Set the <em>width</em>, <em>color</em>, and <em>style</em> of the grid lines.</li>
</ul>
<table style="width: 100%">
  <colgroup>
       <col span="1" style="width: 20%;">
       <col span="1" style="width: 80%;">
    </colgroup>
<tr>
<th><b>Input</b></th><th>Description</th>
</tr>
<tr>
<td>which_grid</td><td>Specifies which grid line to modify. The options include: <code>"major"</code>, <code>"minor"</code>, or <code>"both"</code>.</td>
</tr>
<tr>
</tr><tr>
<td>width</td><td>Specifies the thickness of the line(s) in pixels. The default value is 1.</td>
</tr>
<tr>
<td>color</td><td>Optional argument, specifying the name or RGB value of the new color(s) for the line(s).</td>
</tr>
<tr>
<td>style</td><td>Optional argument, the style(s) of the pen for the line(s). <br>Options include: <table><tr><td>1</td><td>Solid line</td></tr><tr><td>2</td><td>Dash line</td></tr><tr><td>3</td><td>Dot line</td></tr><tr><td>4</td><td>Dash-Dot line</td></tr><tr><td>5</td><td>Dash-Dot-Dot line</td></tr></table></td>
</tr>
</table>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Turn on y-axis grid for the major ticks. Set the
// grid lines to be solid, 1 pixel and light grey
plotSetYGridPen(&amp;myPlot, "major", 1, "Light Grey", 1);</code></pre>
<div class="alert alert-info" role="alert">When using any <code>plotSet</code> procedure, the first input is a pointer to a declared <code>plotControl</code> structure. We indicate that something is a pointer using the <code>&amp;</code> symbol.</div>
<p>Because GAUSS allows us to add and format y-axis and x-axis grid lines separately, we are able to improve readability with y-axis lines without adding the clutter of a full grid. </p>
<h4 id="customizing-x-axis-ticks">Customizing X-Axis Ticks</h4>
<p>Next, let's turn our attention to the x-axis ticks. We will use three GAUSS procedures to help us customize our ticks:</p>
<table style="width: 100%">
  <colgroup>
       <col span="1" style="width: 20%;">
       <col span="1" style="width: 80%;">
    </colgroup>
<tr>
<th><b>Procedure</b></th><th>Description</th>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotsetxticlabel.html"><code>plotSetXTicLabel</code></a></td><td>Controls the formatting and angle of x-axis tick labels for 2-D graphs.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotsetxticinterval.html"><code>plotSetXTicInterval</code></a></td><td>Controls the interval between x-axis tick labels and also allows the user to specify the first tick to be labeled for 2-D graphs.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotsetticlabelfont.html"><code>plotSetTicLabelFont</code></a></td><td>Controls the font name, size and color for the X and Y axis tick labels.</td>
</tr>
</table>
<p>First, let's change the format of the labels on the x-axis to indicate months rather than quarters:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Display 4 digit year and month on 'X' tick labels
plotSetXTicLabel(&amp;myPlot, "YYYY-MO");</code></pre>
<div class="alert alert-info" role="alert">A full list of supported x-axis tick label formats for time series data is available in the <strong>Remarks</strong> section of the <a href="https://docs.aptech.com/gauss/plotsetxticlabel.html">documentation for <code>plotSetXTicLabel</code></a>.</div>
<p>Second, let's set the x-axis ticks to:</p>
<ul>
<li>Start in March of 2020 to correspond with the start of the pandemic.</li>
<li>Occur every 3 months. </li>
</ul>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Place first 'X' tick mark on March 1st, 2020
// with ticks occurring every 3 months
plotSetXTicInterval(&amp;myPlot, 3, "months", asDate("2020-03"));</code></pre>
<p>Third, let's increase the size of the axis tick labels:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Change tic label font size
plotSetTicLabelFont(&amp;myPlot, "Arial", 12); </code></pre>
<h4 id="updating-axis-labels">Updating Axis Labels</h4>
<p>Finally, we change the axis labels:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Specify the text for the Y-axis label as well as
// the font and font size for both labels
plotSetYLabel(&amp;myPlot, "Cases per 100k", "Arial", 14);

// Specify text for the x-axis label
plotSetXLabel(&amp;myPlot, "Date");</code></pre>
<div class="alert alert-info" role="alert">The<code>plotSetYLabel</code> and <code>plotSetXLabel</code> functions automatically set the font, font size, and font color for both axes. There is no need to specify it again.</div>
<p>Now we can create our formatted graph:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Plot COVID cases per 100K by state. Pass in the 'plotControl'
// structure, 'myPlot', to use the settings we applied above.
plotXY(myPlot, covid_cases, "cases_avg_per_100k ~ date + by(state)");</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-first-round.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-first-round.jpg" alt="" width="753" height="566" class="alignnone size-full wp-image-11582243" /></a></p>
<h2 id="highlighting-events">Highlighting Events</h2>
<p>It's common with time series plots that we want to note specific dates or periods on the graph. GAUSS includes four functions, introduced in GAUSS 22, that make highlighting events easy.</p>
<table style="width: 100%">
  <colgroup>
       <col span="1" style="width: 20%;">
       <col span="1" style="width: 40%;">
       <col span="1" style="width: 40%;">
    </colgroup>
<tr>
<th><b>Procedure</b></th><th>Description</th><th>Example</th>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotaddvline.html"><code>plotAddVLine</code></a></td><td>Adds one or more vertical lines to an existing plot.</td><td><code>plotAddVLine("2020-01-01");</code></td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotaddvbar.html"><code>plotAddVBar</code></a></td><td>Adds one or more vertical bars spanning the full extent of the y-axis to an existing graph.</td><td><code>plotAddVBar("2020-01", "2020-03");</code></td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotaddhline.html"><code>plotAddHLine</code></a></td><td>Adds one or more horizontal lines to an existing plot.</td><td><code>plotAddHLine(500);</code></td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotaddhbar.html"><code>plotAddHBar</code></a></td><td>Adds one or more horizontal bars spanning the full extent of the x-axis to an existing graph.</td><td><code>plotAddHBar(580, 740);</code></td>
</tr>
</table>
<p>As an example, let's add vertical lines to help compare July 4th, 2020 to July 4th, 2021. </p>
<h3 id="specifying-legend-behavior-when-adding-lines">Specifying Legend Behavior When Adding Lines</h3>
<p>First, when adding new data to an existing plot, we need to specify how we want this data treated on the legend using the <a href="https://docs.aptech.com/gauss/plotsetlegend.html"><code>plotSetLegend</code></a> procedure. </p>
<p>We can add a label for the line to the legend:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Label next added line "Independence Day"
// and add to the legend
plotSetLegend(&amp;myPlot, "Independence Day");</code></pre>
<p>or we can tell GAUSS to not make any changes to the current legend:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// The empty string specifies that the legend 
// should remain unchanged when the next line is added.
plotSetLegend(&amp;myPlot, "");</code></pre>
<h3 id="specifying-line-style">Specifying Line Style</h3>
<p>Next, we will specify the style of our lines using the <a href="https://docs.aptech.com/gauss/plotsetlinepen.html"><code>plotSetLinePen</code></a> procedure. This procedure lets us set the <em>width</em>, <em>color</em>, and <em>style</em> of the lines added to the graph. </p>
<table style="width: 100%">
  <colgroup>
       <col span="1" style="width: 20%;">
       <col span="1" style="width: 80%;">
    </colgroup>
<tr>
<th><b>Attribute</b></th><th>Description</th>
</tr>
<tr>
<td>width</td><td>Specifies the thickness of the line(s) in pixels. The default value is 2.</td>
</tr>
<tr>
<td>color</td><td>Optional argument, specifying the name or RGB value of the new color(s) for the line(s).</td>
</tr>
<tr>
<td>style</td><td>Optional argument, the style(s) of the pen for the line(s). <br>Options include: <table><tr><td>1</td><td>Solid line</td></tr><tr><td>2</td><td>Dash line</td></tr><tr><td>3</td><td>Dot line</td></tr><tr><td>4</td><td>Dash-Dot line</td></tr><tr><td>5</td><td>Dash-Dot-Dot line</td></tr></table></td>
</tr>
</table>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set the line width to be 2 pxs
// the line color to be #555555
// and the line to be dashed
plotSetLinePen(&amp;myPlot, 2, "#555555", 2);</code></pre>
<h3 id="adding-lines-to-mark-events">Adding Lines to Mark Events</h3>
<p>Finally, let's add the lines marking Independence Day in 2020 and 2021. </p>
<p>We first specify the dates we want to add lines using <a href="https://docs.aptech.com/gauss/asdate.html"><code>asDate</code></a>:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create string array of independence days
ind_days = asDate("2020-07-04"$|"2021-07-04");</code></pre>
<p>Then we add our holidays to the existing graph using <code>plotAddVLine</code>:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Add holidays to graph
plotAddVLine(myPlot, ind_days);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-event-lines-revised.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-event-lines-revised.jpg" alt="" width="753" height="566" class="alignnone size-full wp-image-11582294" /></a></p>
<p>The complete code for adding the lines looks like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Do not add vertical lines to the legend
plotSetLegend(&amp;myPlot, "");

// Set the line width to be 2 pixels
// the line color to be a dark grey color, #555555,
// and the line to be dashed
plotSetLinePen(&amp;myPlot, 2, "#555555", 2);

// Create string array of independence days
ind_days = asDate("2020-07-04"$|"2021-07-04");

// Add holidays to graph
plotAddVline(myPlot, ind_days);</code></pre>
<h3 id="adding-bars-to-mark-events">Adding Bars to Mark Events</h3>
<p>Now, let's add a vertical bar to mark the winter holidays time period of 2020. We will add a bar that marks the time span from Thanksgiving 2020 to New Year's Day 2021. </p>
<p>We first need to create a new <code>plotControl</code> structure to format our bars. Since we are adding a bar to the graph, we will fill our new <code>plotControl</code> structure with the defaults for a bar graph:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create plotControl structure
struct plotControl plt;

// Fill with default bar settings
plt = plotGetDefaults("bar");</code></pre>
<p>Next, we can format our bar using the <a href="https://docs.aptech.com/gauss/plotsetfill.html"><code>plotSetFill</code></a> procedure. The <code>plotSetFill</code> procedure allows us to control the <em>fill style</em>, <em>opacity</em>, and <em>color</em> of graphed bars:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set bar to have solid fill with 20% opacity
// and grey color
plotSetFill(&amp;plt, 1, 0.20, "grey");</code></pre>
<p>We also have to specify the legend behavior when the bar is added. This time let's add a label to the legend for the &quot;Winter Holidays&quot;:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Add "Winter Holidays" to the legend
plotSetLegend(&amp;plt, "Winter&lt;br&gt;Holidays");</code></pre>
<div class="alert alert-info" role="alert">The code <code>&lt;br&gt;</code> is HTML and it tells GAUSS to line break between the words <code>"Winter"</code> and <code>"Holidays"</code>. </div>
<p>Now we are ready to add the bar to our graph using the <a href="https://docs.aptech.com/gauss/plotaddvbar.html"><code>plotAddVBar</code></a> procedure:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Add a vertical bar to graph starting 
// on November 26th, 2020 and 
// ending January 1st, 2021
plotAddVBar(plt, asDate("2020-11-26"), asDate("2021-01"));</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-add-bar.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-add-bar.jpg" alt="" width="753" height="566" class="alignnone size-full wp-image-11582296" /></a></p>
<h2 id="adding-notes-to-graphs">Adding Notes to Graphs</h2>
<p>As final customization, let's add a note to our graph to label one of our holidays. We can do this using the <a href="https://docs.aptech.com/gauss/plotaddtextbox.html"><code>plotAddTextBox</code></a> procedure. </p>
<p>The <code>plotAddTextBox</code>takes three required inputs:</p>
<ul>
<li>The text to be added to the graph. </li>
<li>The x location where the text should start.</li>
<li>The y location where the text should start. </li>
</ul>
<div class="alert alert-info" role="alert">An optional <code>plotAnnotation</code> structure can be used to format the textbox and its text content. </div>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Label the 2020 Independence Day line
plotAddTextBox("&amp;larr; Independence Day", asDate("2020-07-04"), 80);</code></pre>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-final-rev2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/12/covid-cases-final-rev2.jpg" alt="" width="753" height="566" class="alignnone size-full wp-image-11582298" /></a></p>
<div class="alert alert-info" role="alert">The code <code>&amp;larr;</code> is HTML and it tells GAUSS to add a left arrow to the graph. </div>
<h2 id="conclusion">Conclusion</h2>
<p>In this blog, we see how a few customizations and enhancements can make plots easier to read and more impactful. </p>
<p>In particular, we covered:</p>
<ul>
<li>Using grid lines without cluttering a graph. </li>
<li>Changing tick labels for readability. </li>
<li>Using clear axis labels. </li>
<li>Marking events and outcomes with lines, bars, and annotations. </li>
</ul>
<h3 id="further-reading">Further Reading</h3>
<ul>
<li><a href="https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/">How to Create Tiled Graphs in GAUSS</a></li>
<li><a href="https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/">How to Interactively Create Reusable Graphics Profiles</a></li>
<li><a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/">Five Hacks For Creating Custom GAUSS Graphics</a></li>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/">How to Mix, Match, and Style Different Graph Types</a></li>
</ul>
<h2 id="references">References</h2>
<p>&quot;The New York Times. (2021). Coronavirus (Covid-19) Data in the United States. Retrieved 12-05-2021, from <a href="https://github.com/nytimes/covid-19-data">https://github.com/nytimes/covid-19-data</a>.&quot;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>How to Create Tiled Graphs in GAUSS</title>
		<link>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/</link>
					<comments>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 04 Aug 2020 17:07:24 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=22489</guid>

					<description><![CDATA[Placing graphs next to each other can be a great way to present information and improve data visualization. Today we will learn how to create tiled graphs in GAUSS with the easy-to-use <a href="https://docs.aptech.com/gauss/plotlayout.html">plotLayout</a> procedure. <br>
<br>
We will work through two simple examples where you will learn:
<ul>
<li>How to created tiled layouts which are uniform and layouts with graphs of different sizes.</li>
<li>Which graph types can be used with <strong>plotLayout</strong>.</li>
<li>How to clear your tiled graph layouts.</li>
</ul>
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Placing graphs next to each other can be a great way to present information. Today we will learn how to create tiled graphs in GAUSS using <a href="https://docs.aptech.com/gauss/plotlayout.html"><code>plotLayout</code></a>. </p>
<p>We will work through two simple examples where you will learn:</p>
<ul>
<li>How to created tiled layouts which are uniform and layouts with graphs of different sizes.</li>
<li>Which graph types can be used with <code>plotLayout</code>.</li>
<li>How to clear your tiled graph layouts.</li>
</ul>
<h2 id="how-to-use-plotlayout">How to use plotLayout</h2>
<p>In GAUSS, <code>plotLayout</code> allows you to arrange multiple graphs in a tiled layout. It takes the following inputs:</p>
<hr>
<dl>
<dt>g_rows</dt>
<dd>The number of rows in the graph grid.</dd>
<dt>g_cols</dt>
<dd>The number of columns in the graph grid.</dd>
<dt>idx</dt>
<dd>The cell in which to place the next graph, walking along the rows.
<hr></dd>
</dl>
<p>Therefore, the call:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotLayout(2, 3, idx);</code></pre>
<p>will:</p>
<ol>
<li>Split the graph canvas into a 2x3 grid. </li>
<li>Place the next graph in the cell corresponding to the value of <code>idx</code> as shown below.</li>
</ol>
<div>
<table>
<tr height="100 px"><td>idx = 1</td><td>idx = 2</td><td>idx = 3</td></tr>
<tr height="100 px"><td>idx = 4</td><td>idx = 5</td><td>idx = 6</td></tr>
</table>
</div>
<div class="alert alert-info" role="alert"><strong>Note</strong>: <code>plotLayout</code> does not actually alter the graph canvas. It computes and stores the coordinates needed to place your graph tile.</div>
<h2 id="which-graph-types-can-be-used-with-plotlayout">Which Graph Types Can be Used with plotLayout?</h2>
<p>Below is a partial list of the GAUSS graph functions which can be used with <code>plotLayout</code>. Each cell is independent and may contain a different graph type.</p>
<table>
<thead>
<tr>
<th>Function</th>
<th>Graph type</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotxy.html">plotXY</a></td>
<td>XY line.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotscatter.html">plotScatter</a></td>
<td>2-D Scatter.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotts.html">plotTS</a></td>
<td>Time series line.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plottshf.html">plotTSHF</a></td>
<td>High frequency and irregular time series lines.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotbar.html">plotBar</a></td>
<td>2-D bars.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotbox.html">plotBox</a></td>
<td>Box plots.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plothist.html">plotHist</a>, <a href="https://docs.aptech.com/gauss/plothistp.html">plotHistP</a></td>
<td>Standard and percentage histograms.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotlogx.html">plotLogX</a>, <a href="https://docs.aptech.com/gauss/plotlogy.html">plotLogY</a>, <a href="https://docs.aptech.com/gauss/plotloglog.html">plotLogLog</a></td>
<td>Line plot where one or more of the axes are in log space.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotcontour.html">plotContour</a></td>
<td>Contours.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotarea.html">plotArea</a></td>
<td>Stacked area.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotxyfill.html">plotXYFill</a></td>
<td>Area between two vectors.</td>
</tr>
</tbody>
</table>
<h2 id="example-1-uniform-grid-layout">Example 1: Uniform Grid Layout</h2>
<p>Now that we have seen the basics of <code>plotLayout</code>, let's put together a simple example placing 4 graphs in a 2x2 grid.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Create the vector 0.1, 0.2, 0.3...3.0
x = seqa(0.1, 0.1, 30);

/*
** First subplot
*/

// Divide the graph canvas into a 2x2 grid
// and place the next graph in the 1st cell
plotLayout(2, 2, 1);

// Create 'y1' and draw graph
y1 = exp(x);
plotXY(x, y1);

/*
** Second subplot
*/
plotLayout(2, 2, 2);

y2 = sin(x);
plotXY(x, y2);

/*
** Third subplot
*/
plotLayout(2, 2, 3);

y3 = cos(x);
plotXY(x, y3);

/*
** Fourth subplot
*/
plotLayout(2, 2, 4);

y4 = ln(x);
plotXY(x, y4);</code></pre>
<p>After running the above code, you should see a graph that looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-1.jpg" alt="Simple GAUSS tiled graph." width="600" height="450" class="aligncenter size-full wp-image-22523" /></a></p>
<h3 id="clearing-the-plot-layout">Clearing the Plot Layout</h3>
<p>What do you think would happen if we created another plot right after running the code from the previous section? Let's try it with the code below.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create new 'y' by adding uniform random
// numbers to the 'x' created above
y = x + rndu(30,1);

// Draw graph
plotScatter(x, y);</code></pre>
<p>This time your graph should look like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-2.jpg" alt="Subplots in GAUSS." width="600" height="450" class="aligncenter size-full wp-image-22528" /></a></p>
<p>As we can see, GAUSS remembers the grid we created with our last call to <code>plotLayout</code> as well as the chosen cell index. This state will persist until one of the following statements has been executed:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Subsequent graphs will fill the entire graph canvas.
plotClearLayout();</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// 1. Clear all data from the GAUSS workspace.
// 2. Clear the current plot layout state, so that new graphs will fill the entire graph canvas.
new;</code></pre>
<h2 id="example-2-mixed-size-grid-layout">Example 2: Mixed Size Grid Layout</h2>
<p>Sometimes your graphs will look better with tiles of different sizes. Fortunately, as we saw earlier, <code>plotLayout</code> only computes and stores coordinates.</p>
<p>Therefore, each call to <code>plotLayout</code> is independent of any previous calls. As long as your graph tiles do not overlap, each call to <code>plotLayout</code> may use a different grid size. This allows you to mix graphs of different sizes in the same graph canvas. </p>
<p>Let's modify our previous example, so that the third graph takes up the entire second row.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Create the vector 0.1, 0.2, 0.3...3.0
x = seqa(0.1, 0.1, 30);

/*
** First subplot
*/

// Divide the graph canvas into a 2x2 grid
// and place the next graph in the 1st cell
plotLayout(2, 2, 1);

// Create 'y1' and draw graph
y1 = exp(x);
plotXY(x, y1);

/*
** Second subplot
*/
plotLayout(2, 2, 2);

y2 = sin(x);
plotXY(x, y2);

/*
** Third subplot
**
**     Change to interpret the graph canvas
**     as a 2x1 grid and place the next graph
**     in the second cell.
*/
plotLayout(2, 1, 2);

y3 = cos(x);
plotXY(x, y3);</code></pre>
<p>In this code example, we changed the inputs to <code>plotLayout</code> instructing it to:</p>
<ul>
<li>Split the graph canvas into a grid with 2 rows and 1 column.</li>
<li>Place the next graph in the second cell.</li>
</ul>
<p>This results in the graph below with the third plot taking up the entire second row of the graph canvas.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-mixed-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-mixed-1.jpg" alt="Tiled GAUSS graphs of different sizes." width="600" height="450" class="aligncenter size-full wp-image-22535" /></a></p>
<h3 id="conclusion">Conclusion</h3>
<p>Congratulations, you now have another tool in your graph creating toolbox! You have learned how to: </p>
<ol>
<li>Create tiled graphics in GAUSS.</li>
<li>Create uniform and mixed size layouts.</li>
<li>Clear the plot layout grid.</li>
</ol>
<h3 id="next-steps">Next Steps</h3>
<ul>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/">How to Mix, Match and Style Different Graph Types.</a></li>
<li><a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/">Five Hacks For Creating Custom GAUSS Graphics.</a></li>
<li><a href="https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/">How to Interactively Create Reusable Graphics Profiles.</a></li>
</ul>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Interactively Create Reusable Graphics Profiles</title>
		<link>https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/</link>
					<comments>https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Thu, 07 May 2020 19:41:03 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[User Interface]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=21922</guid>

					<description><![CDATA[Learn how to create reusable graphics profiles with a few clicks of your mouse.]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>You probably know that you can use GAUSS code to create repeatable styling for your graphs. However, you might not know that GAUSS also allows you to build reusable graphics profiles with a few clicks of your mouse.</p>
<p>We will show you how to clone existing graphics profiles and how to control:</p>
<ul>
<li>Font settings for the title, axes labels, and tick labels.</li>
<li>Line colors and styles.</li>
<li>Legend location and styling.</li>
</ul>
<p>While this tutorial will not cover all available options, you should learn enough to be comfortable making most other changes without additional help.</p>
<h2 id="our-project">Our Project</h2>
<p>For this tutorial, our goal will be to create a graph profile to replicate the style of the graph below. <a href="https://github.com/aptech/gauss_blog/tree/master/graphics/interactive-graphics-profiles-05.07.20">Data for the graph can be downloaded from here</a>.</p>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profiles-cook-county-final-1.jpg"><img src="/wp-content/uploads/2020/05/blog-graph-profiles-cook-county-final-1.jpg" alt="" width="520" height="400" class="aligncenter size-full wp-image-21996" /></a></p>
<h2 id="video-tutorial">Video Tutorial</h2>
<iframe width="560" height="315" src="https://www.youtube.com/embed/qwcP1wFOTXc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<p>This video tutorial will show you how to:</p>
<ol>
<li>Clone an Existing Graph Profile.</li>
<li>Modify Title and Axis Font Settings.</li>
<li>Modify Line Style and Legend Descriptions.</li>
<li>Set the Legend Properties.</li>
<li>Set the Y-axis Label.</li>
</ol>
<p>or read the text instructions below.</p>
<h2 id="step-1-clone-an-existing-graph-profile">Step 1: Clone an Existing Graph Profile</h2>
<p><a href="/wp-content/uploads/2020/05/blog-create-graph-profile-round-2.jpg"><img src="/wp-content/uploads/2020/05/blog-create-graph-profile-round-2.jpg" alt="Create GAUSS graphics profile." width="1916" height="754" class="aligncenter size-full wp-image-21965" /></a></p>
<ol>
<li>Select <strong>Tools &gt; Preferences</strong> from the main GAUSS menu.<br/></li>
<li>Select <strong>Graphics</strong> on the left side of the <strong>Preferences</strong> window.<br/></li>
<li>Select the <strong>Profiles</strong> button at the top of the <strong>Graphics Preferences</strong>.<br/></li>
<li>Select the profile you would like to clone from the dropdown list.<br/></li>
<li>Select the <strong>Clone</strong> button.<br/></li>
<li>Enter the name for your new profile and click <em>OK</em>.<br/></li>
</ol>
<h2 id="step-2-modify-font-settings">Step 2: Modify Font Settings</h2>
<h3 id="set-the-title-font">Set the Title Font</h3>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profile-title-font-round.jpg"><img src="/wp-content/uploads/2020/05/blog-graph-profile-title-font-round.jpg" alt="Modify graphics profile title font." width="1614" height="710" class="aligncenter size-full wp-image-21967" /></a></p>
<p>Using the graphics profile created in the previous step:</p>
<ol>
<li>Select <strong>Title</strong> from the list of graph settings on the left.<br/></li>
<li>Click <strong>Change</strong> button on the right.<br/></li>
</ol>
<p>This will open your operating system's font dialog, where you can select your desired font, weight, and size:</p>
<p><a href="/wp-content/uploads/2020/05/blog-create-graph-profiles-font-dialog.jpg"><img src="/wp-content/uploads/2020/05/blog-create-graph-profiles-font-dialog.jpg" alt="" width="363" height="203" class="aligncenter size-full wp-image-21952" /></a></p>
<h3 id="set-the-axes-label-and-tick-label-fonts">Set the Axes Label and Tick Label Fonts</h3>
<p><a href="/wp-content/uploads/2020/05/blog-create-graph-profile-axes-font-round.jpg"><img src="/wp-content/uploads/2020/05/blog-create-graph-profile-axes-font-round.jpg" alt="Set axes fonts for GAUSS graphics profile." width="1502" height="654" class="aligncenter size-full wp-image-21970" /></a></p>
<ol>
<li>Select <strong>Axes Style</strong> from the list of graph settings on the left.<br/></li>
<li>From the <em>Caption</em> section, select the <strong>Change</strong> button to modify the axes label font.<br/></li>
<li>Click the <em>Numbers</em> <strong>Change</strong> button and select your preferred font settings for the tick labels.<br/></li>
</ol>
<h2 id="step-3-modify-line-style-and-legend-descriptions">Step 3: Modify Line Style and Legend Descriptions</h2>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profile-create-line-style.png"><img src="/wp-content/uploads/2020/05/blog-graph-profile-create-line-style.png" alt="Modify line style, legend entry and color for GAUSS graphics preference." width="1240" height="674" class="aligncenter size-full wp-image-21973" /></a></p>
<p>We'll start by modifying the third line which marks the date of the first U.S. location transmission.</p>
<ol>
<li>Select <strong>Series 3</strong>.</li>
<li>Enter the legend text for this line in the <strong>Legend Title</strong> text input box.</li>
<li>Double-click the color box next to <strong>Line Color</strong> and select a gray color.</li>
<li>Select <em>Dash Line</em> from the dropdown box next to <strong>Style</strong>.</li>
</ol>
<p>Then repeat step 2 above to add the legend text for <strong>Series 1</strong> and <strong>Series 2</strong>.</p>
<h2 id="step-4-set-the-legend-properties">Step 4: Set the Legend Properties</h2>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profile-legend-options.jpg"><img src="/wp-content/uploads/2020/05/blog-graph-profile-legend-options.jpg" alt="Modify legend location, font and border color for GAUSS graphic profile." width="748" height="445" class="aligncenter size-full wp-image-21977" /></a></p>
<ol>
<li>Select <strong>Legend</strong>.</li>
<li>Click the font <strong>Change</strong> button and set the desired font and font size.</li>
<li>Select the legend location, using the <em>Vertical Position</em>, <em>Horizontal Position</em>, <em>Inside/Outside</em> and <em>Orientation</em> options.</li>
<li>Double-click the color box next to <strong>Line Color</strong> and set it to white so the legend outline is unseen.</li>
</ol>
<h2 id="step-5-set-y-axis-label">Step 5: Set Y-axis Label</h2>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profile-axes-label.jpg"><img src="/wp-content/uploads/2020/05/blog-graph-profile-axes-label.jpg" alt="Set axes labels in GAUSS graph profile." width="408" height="345" class="aligncenter size-full wp-image-21980" /></a></p>
<ol>
<li>Select <strong>Axes Text</strong>.</li>
<li>Enter the desired axis label in the appropriate text box.</li>
</ol>
<h2 id="use-the-custom-graphics-profile">Use the Custom Graphics Profile</h2>
<p>You can access the settings from a graph profile using the <code>plotGetDefaults</code> function as you would for the default settings. Below is a simple example.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load variables
Y = loadd("cook-county-covid.csv", "cases + deaths");

x = seqa(1, 1, rows(Y));

// Declare myPlot to be a plotControl structure
// and fill with the settings from our covid profile
struct plotControl myPlot;
myPlot = plotGetDefaults("covid");

// Draw plot using covid profile settings
plotXY(myPlot, x, Y);</code></pre>
<p>which will produce the plot below:</p>
<p><a href="/wp-content/uploads/2020/05/blog-graph-profiles-xy-with-profile-1.jpg"><img src="/wp-content/uploads/2020/05/blog-graph-profiles-xy-with-profile-1.jpg" alt="XY graph using custom graphics profile." width="520" height="400" class="aligncenter size-full wp-image-21990" /></a></p>
<h3 id="further-customize">Further Customize</h3>
<p>While the graphs for a given project may share many features, it is likely that some attributes such as the title or legend text will need to be different. You could clone your custom profile and make these changes. However, it might be simpler to make these changes in your code.</p>
<p>Fortunately, you can use the <code>plotSet</code> functions to further customize the settings for a particular graph. You can modify any settings that you would like to change. </p>
<p>The code below shows how to change the title, keeping all other settings unchanged.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load variables
Y = loadd("cook-county-covid.csv", "cases + deaths");

x = seqa(1, 1, rows(Y));

// Declare myPlot to be a plotControl structure
// and fill with the settings from our covid profile
struct plotControl myPlot;
myPlot = plotGetDefaults("covid");

// Set title text
plotSetTitle(&amp;myPlot, "COVID-19 Cook County");

// Draw plot using covid profile settings
plotXY(myPlot, x, Y);</code></pre>
<p>These settings will not modify the custom graphics profile that you created. Next time you call <code>myPlot = plotGetDefaults("covid")</code>, <code>myPlot</code> will be filled with the custom profile settings that you selected in the <strong>Preferences</strong> dialog window.</p>
<h2 id="full-code-for-time-series-plot">Full Code for Time Series Plot</h2>
<p>Full code to create the time series plot shown at the top of this post, using the &quot;covid&quot; custom graphics profile we created, can be <a href="https://github.com/aptech/gauss_blog/tree/master/graphics/interactive-graphics-profiles-05.07.20">downloaded here</a>.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Great job! You've learned how to interactively create custom graphics profiles that can be easily reused and further modified.</p>
<h3 id="next-steps">Next Steps</h3>
<ul>
<li><a href="/blog/how-to-mix-match-and-style-different-graph-types/">How to Mix, Match and Style Different Graph Types</a>.</li>
<li><a href="/blog/five-hacks-for-creating-custom-gauss-graphics/">Five Hacks For Creating Custom GAUSS Graphics</a>.</li>
<li><a href="/blog/graph-high-frequency-forex-data/">Graph high-frequency Forex data</a>.</li>
</ul>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to mix, match and style different graph types</title>
		<link>https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/</link>
					<comments>https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 20 Aug 2019 17:56:02 +0000</pubDate>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=20651</guid>

					<description><![CDATA[Often times we need to mix multiple graph types in order to create a plot which most effectively tells the story of our data. In this post, we will create a plot of the Phillips Curve in the United States over two separate time periods. We will show how to add scatter points and lines as well as data series' of different lengths to a single plot. However, our main focus will be showing you how to control the styling of all aspects of the plot in these cases.]]></description>
										<content:encoded><![CDATA[<h3 id="intro">Intro</h3>
<p>Often times we need to mix multiple graph types in order to create a plot which most effectively tells the story of our data. In this post, we will create a plot of the Phillips Curve in the United States over two separate time periods. </p>
<p>We will show how to add scatter points and lines as well as data series' of different length to a single plot. However, our main focus will be showing you how to control the styling of all aspects of the plot in these cases.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-main.jpg"><img src="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-main.jpg" alt="" width="680" height="400" class="aligncenter size-full wp-image-20667" /></a></p>
<h2 id="how-to-add-data-to-an-existing-graph">How to add data to an existing graph</h2>
<p>The main GAUSS graphing functions shown in the second column of the table below, treat each column of the input data as a separate series. This makes it very simple to plot data in which the plot type and series length are the same.</p>
<table>
<thead>
<tr><th>Plot type</th><th>Main function</th><th>Add function</th></tr>
</thead>
<tbody>
<tr><td>Scatter</td><td>plotScatter</td><td>plotAddScatter</td></tr>
<tr><td>XY</td><td>plotXY</td><td>plotAddXY</td></tr>
<tr><td>Time Series</td><td>plotTS, plotTSHF</td><td>plotAddTS, plotAddTSHF</td></tr>
<tr><td>Bar / Histogram</td><td>plotBar, plotHist, plotHistF, plotHistP</td><td>plotAddBar, plotAddHist, plotAddHistF, plotAddHistP</td></tr>
<tr><td>Box</td><td>plotBox</td><td>plotAddBox</td></tr>
</tbody>
</table>
<p>We can add a new series to a graph created with one of the <em>main</em> functions in column two, by using one of the <em>add</em> functions in column three. </p>
<p>The <em>add</em> functions take the same inputs as the <em>main</em> functions. For example, the code below will create a scatter plot and then add a line at the mean of the Y variable.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load variables from dataset
data = loadd("phillips-us-1955.csv", "CPI + Unemployment");

// Plot initial scatter points
plotScatter(data[.,1], data[.,2]);

// Compute mean of unemployment
mu_u = meanc(data[.,2]);

// Compute range of CPI
range_cpi = minc(data[.,1]) | maxc(data[.,2]);

// Add a line across the range of the CPI
// data at the height of the average of the
// Unemployment data
plotAddXY(range_cpi, mu_u | mu_u);</code></pre>
<p>The code will create a graph which looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-1.jpg" alt="" width="400" height="300" class="aligncenter size-full wp-image-20669" /></a></p>
<h2 id="how-to-style-a-graph-with-plotadd-functions">How to style a graph with plotAdd functions</h2>
<p>When styling graphs made with <code>plotAdd</code> functions, an important distinction is made between axis level attributes and series level attributes.</p>
<h3 id="axis-level-attributes">Axis level attributes</h3>
<p>Axis level attributes are the elements which are generally independent of the data. For example, the title, axes labels and tick labels are axis level attributes. These attributes become fixed during the creation of the initial plot and cannot be modified with a <code>plotAdd</code> call.</p>
<p>The axis level attributes include:</p>
<ul>
<li>Title</li>
<li>Axes labels</li>
<li>Tick label font and format</li>
<li>Axes line attributes</li>
<li>X and Y-axis range (if explicitly set with <code>plotSetXRange</code> / <code>plotSetYRange</code>)</li>
<li>Canvas size</li>
<li>Legend location, font and background style</li>
</ul>
<p>For example, if we modify our earlier code like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load variables from dataset
data = loadd("phillips-us-1955.csv", "CPI + Unemployment");

struct plotControl myPlot;
myPlot = plotGetDefaults("scatter");

// Set axis element, title
plotSetTitle(&amp;myPlot, "Phillips Curve in the US", "Helvetica Neue", 14);

// Plot initial scatter points
// Note that we pass in 'myPlot' this time
plotScatter(myPlot, data[.,1], data[.,2]);

// Compute mean of unemployment
mu_u = meanc(data[.,2]);

// Compute range of CPI
range_cpi = minc(data[.,1]) | maxc(data[.,2]);

// Attempt to reset axis level property
myPlot = plotGetDefaults("xy");
plotSetTitle(&amp;myPlot, "Title which will be ignored");

// Attempt to set axis level property
plotSetXLabel(&amp;myPlot, "CPI");

// Add a line across the range of the CPI
// data at the height of the average of the
// Unemployment data
// Note that we pass in 'myPlot' this time
plotAddXY(myPlot, range_cpi, mu_u | mu_u);</code></pre>
<p>we will get a graph that looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-2.jpg" alt="" width="400" height="300" class="aligncenter size-full wp-image-20672" /></a></p>
<p>The code reset the title before the <code>plotAddXY</code> call from &quot;Phillips Curve in the US&quot; to &quot;Title which will be ignored&quot;. The code also reset the X-axis label from nothing to &quot;CPI&quot;. As you see both of those changes were ignored because axis level attributes must be set on the initial plot creation.</p>
<h3 id="series-level-attributes">Series level attributes</h3>
<p>Series level attributes are those settings which are specific to the data series. For example, line color, line thickness and scatter symbol are all series level attributes. </p>
<p>The series level attributes include:</p>
<ul>
<li>Line color, thickness, style</li>
<li>Scatter symbol type, color</li>
<li>Legend text</li>
</ul>
<p>You have the choice whether to set the series level attributes at the time of the initial plot call or to modify them during the <code>plotAdd</code>. Passing a <code>plotControl</code> structure to the <code>plotAdd</code> call tells GAUSS to update the series level attributes. If you do not pass a <code>plotControl</code> structure to the <code>plotAdd</code> call, GAUSS will continue using the attributes set in the initial plot creation.</p>
<p>More specifically, when a <code>plotControl</code> structure is not passed into the <code>plotAdd</code> call, GAUSS will continue cycling through the previously set series attributes where the last plot call left off. It is like the last plot call left a bookmark in the list of series attributes.</p>
<p>For example, you may have noticed that the mean line in the first graph we made is blue, while the line in the second graph is orange. Looking at the default colors in the table below, we can see why.</p>
<table>
<tr><th colspan="5" style="text-align: center">Default colors</th></tr>
<tr><td>#FC8D62</td><td>#8DA0CB</td><td>#66C2A5</td><td>#E78AC3 </td><td>#A6D854</td></tr>
<tr><td style="background-color:#FC8D62"> </td><td style="background-color:#8DA0CB"> </td><td style="background-color:#66C2A5"> </td><td style="background-color:#E78AC3"> </td><td style="background-color:#A6D854"> </td></tr>
</table>
<p>When we created the first graph, the initial <code>plotScatter</code> call set the graph's line and scatter symbol colors to the list of five colors shown above. The initial scatter plot used the first orange color, so the <code>plotAddXY</code> without a <code>plotControl</code> structure started with the blue color next in the list.</p>
<p>In the second graph, since the <code>plotAddXY</code> call was given a <code>plotControl</code> structure, this told GAUSS to create the new line using the series settings from the new <code>plotControl</code> structure starting from the beginning. Since we had not changed the sequence of colors, the added mean line used the same orange color as the scatter plot.</p>
<h2 id="how-to-create-the-full-phillips-curve-graph">How to create the full Phillips Curve graph</h2>
<p>It is generally considered a best practice to apply all axes and series level settings with the initial plot call. That is what we will do here. Our steps will be:</p>
<ol>
<li>Load the data.</li>
<li>Set the axis level attributes.</li>
<li>Set the series level attributes.</li>
<li>Draw the initial scatter plot.</li>
<li>Add the second set of scatter points.</li>
<li>Add the two regression lines.</li>
</ol>
<h3 id="step-1-load-and-define-data">Step 1: Load and define data</h3>
<p>We will start by loading the data for both sets of scatter points. To keep our focus on the graphs, we have simply defined the start and endpoints for the regression lines instead of computing them.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load inflation and unemployment data
// (CPI percent change) for 1955–71 and 1974–84
phil_1955 = loadd("phillips-us-1955.csv", "CPI + Unemployment");
phil_1974 = loadd("phillips-us-1974.csv", "CPI + Unemployment");

// For simplicity, define start and
// end points for regression lines
reg_x_1955 = { -0.8538, 6.4246 };
reg_y_1955 = { 5.6356, 3.8925 };

reg_x_1974 = { 2.3590, 14.5923 };
reg_y_1974 = { 9.0762, 5.9248 };</code></pre>
<h3 id="step-2-set-the-axis-level-attributes">Step 2: Set the axis level attributes</h3>
<p>Next, we will apply the most straightforward axis level settings. The only point to note about these is that they cannot be changed by a <code>plotAdd</code> call.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare 'myPlot' to be a plotControl structure
// and fill with default settings
struct plotControl myPlot;
myPlot = plotGetDefaults("scatter");

plotSetTitle(&amp;myPlot, "Phillips Curve in the US", "Arial", 14);

// Note that the font settings applied in
// plotSetXLabel will control the Y-label font
// as well. Setting the Y-label without font
// settings will leave previous font settings unchanged
plotSetXLabel(&amp;myPlot, "Inflation", "Arial", 14);
plotSetYLabel(&amp;myPlot, "Unemployment");

plotSetYRange(&amp;myPlot, 0, 12.5);</code></pre>
<p>Setting the legend will make us think a little more. We will set the legend background to be completely transparent, that is clearly an axis level setting. </p>
<p>However, the function <code>plotSetLegend</code> allows us to set the legend location which is also an axis level attribute in addition to the text for each item in the legend which is a series level attribute. </p>
<p>Fortunately, since we have decided to set all axis and series level attributes before the first scatter plot, we don't need to worry about this distinction. We simply need to make sure that we set our desired text for every data series we plan to add to the plot.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Make the legend background completely
// transparent, i.e. 0% opacity
plotSetLegendBkd(&amp;myPlot, 0);

// The text for each data series we plan to add
// to our graph, in order. Note that the last
// item is an empty string, "", because we only
// want a legend item for one of the regression lines.
leg_text = "1955-1971" $| "1974-1984" $| "Regression line" $| "";
plotSetLegend(&amp;myPlot, leg_text, "top left inside");</code></pre>
<h3 id="step-3-set-the-series-level-attributes">Step 3: Set the series level attributes</h3>
<p>After setting the legend text, we have one more series level attribute to set. That is the line or scatter symbol color. To keep things simple and focused, we will just use the string hex codes and a text name for the colors.</p>
<p>However, GAUSS has many built-in color palettes which are attractive and easy to use. Our blog post <a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/">5 Hacks for Creating Custom GAUSS Graphics</a> includes a section which links to the available color palettes and the functions needed to access them.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set the colors for the scatter plot, an orange and green
// color, followed by one "black" for each regression line
clrs = "#66C2A5" $| "#FC8D62" $| "black" $| "black";
plotSetLineColor(&amp;myPlot, clrs);</code></pre>
<h3 id="step-4-draw-the-initial-scatter-plot">Step 4: Draw the initial scatter plot</h3>
<p>We'll now draw the initial scatter plot, containing the inflation and unemployment data from 1955 to 1971. We will pass in the <code>plotControl</code> structure which contains all the settings we have applied for every data series we plan to add to the graph.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Draw initial scatter plot
plotScatter(myPlot, phil_1955[.,1], phil_1955[.,2]);</code></pre>
<p>This results in a graph which looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-3.jpg"><img src="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-3.jpg" alt="" width="400" height="300" class="aligncenter size-full wp-image-20670" /></a></p>
<h3 id="step-5-add-the-second-scatter-plot">Step 5: Add the second scatter plot</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Add next scatter series, using previously
// set series level attributes since a
// plotControl structure was not passed in
plotAddScatter(phil_1974[.,1], phil_1974[.,2]);</code></pre>
<p>This code will result in a plot which looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-4.jpg"><img src="https://www.aptech.com/wp-content/uploads/2019/08/philips-plotadd-blog-4.jpg" alt="" width="680" height="400" class="aligncenter size-full wp-image-20679" /></a></p>
<p>Most of this graph should look like you expect. The added scatter plot is using the second legend text item and the second color. The title, axes labels, and Y-axis range have stayed just as we set them. </p>
<p>The X-axis range, however, has changed. Since we made a big deal earlier that axis level attributes do not change after a <code>plotAdd</code>, you may wonder why the X-axis range did not stay the same.</p>
<p>The reason for this is that the default state for the X and Y-axis ranges is to expand to fit the data being drawn. Since we had not set the X-axis range, it remained at &quot;expand to fit data&quot;. </p>
<p>However, if we had set the X-axis range to the range of the first scatter plot, -1 to +7, then the X-axis range would have remained unchanged. This would mean that all data to the right of X=7 would be out of view.</p>
<h3 id="step-6-add-the-regression-lines">Step 6: Add the regression lines</h3>
<p>Since the <code>plotAdd</code> functions, like the standard plot functions, will plot each column of data as a separate series, either of these code snippets will produce the same result:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Option 1: Add the regression lines in separate calls
plotAddXY(reg_x_1955, reg_y_1955);
plotAddXY(reg_x_1974, reg_y_1974);</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Option 2: Add both regression lines in one call
plotAddXY(reg_x_1955 ~ reg_x_1974, reg_y_1955 ~ reg_y_1974);</code></pre>
<p>Remember to only use only one of the above options. This should result in the plot shown at the top of this tutorial.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Congratulations! You have learned:</p>
<ol>
<li>Which plot attributes are axis level elements vs series level elements.</li>
<li>That axis level elements need to be set on the first plot call.</li>
<li>That series level elements can be set on the first plot call, or during a <code>plotAdd</code>, if a <code>plotControl</code> structure is passed in.</li>
</ol>
<p>These concepts you've learned will make it much easier for you to create and style GAUSS graphs with data of different lengths and different plot types.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Five Hacks For Creating Custom GAUSS Graphics</title>
		<link>https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/</link>
					<comments>https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/#respond</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Sat, 16 Mar 2019 13:51:15 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[User Interface]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=19690</guid>

					<description><![CDATA[GAUSS includes a plethora of tools for creating publication-quality graphics. Unfortunately, many people fail to use these tools to their full potential. Today we unlock five advanced GAUSS hacks for building beautiful graphics:  
<ul><li>Using HSL, and Colorbrewer color palettes.</li>
<li>Controlling graph exports.</li>
<li>Changing the plot canvas size.</li>
<li>Annotating graphs with shapes, text boxes, and lines.</li>
<li>Using LaTeX for GAUSS legends, labels and text boxes.</li>
</ul>
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>GAUSS includes a plethora of tools for creating publication-quality graphics. Unfortunately, many people fail to use these tools to their full potential. Today we unlock five advanced GAUSS hacks for building beautiful graphics: </p>
<ol>
<li>Using <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.413.9004&amp;rep=rep1&amp;type=pdf">HSL</a>, <a href="http://www.hsluv.org/">HSLuv</a>, and <a href="http://colorbrewer2.org/#type=sequential&amp;scheme=BuGn&amp;n=3">Colorbrewer</a> color palettes.</li>
<li>Controlling graph exports.</li>
<li>Changing the plot canvas size.</li>
<li>Annotating graphs with shapes, text boxes, and lines.</li>
<li>Using LaTeX for GAUSS legends, labels and text boxes.</li>
</ol>
<h2 id="using-custom-color-palettes">Using custom color palettes</h2>
<img src="https://www.aptech.com/wp-content/uploads/2017/10/wage_scatter_scatter_bar.png" width="320" height="217" alt="Custom GAUSS color palettes" class="aligncenter size-full"/>
<p>GAUSS color schemes include <a href="https://www.aptech.com/releases/gauss18/graphics-updates/color-brewer-palettes/">30 built-in color palettes</a> designed for optimal visual impacts. These include pre-made palettes for sequential, quantitative and diverging data and colorblind friendly palettes.</p>
<p>If you can't find the pre-made palette you like, you can create your own evenly spaced colors in HSL hue space, evenly spaced circular hues in the HSLuv system, or blend custom color palettes. </p>
<p>Color palettes can be controlled using a number of GAUSS procedures:</p>
<table style="width: 100%">
    <colgroup>
       <col span="1" style="width: 25%;">
       <col span="1" style="width: 30%;">
       <col span="1" style="width: 45%;">
    </colgroup>
<tr>
<th>Procedure</th><th>Description</th><th>Format</th>
</tr>
<tr>
<td><b>getColorPalette</b></td><td>Retrieves a named <a href="https://www.aptech.com/releases/gauss18/graphics-updates/color-brewer-palettes/">color palette</a> as a string array.</td><td><i>clrs</i> = <b>getColorPalette</b>(<i>name</i>);<br>
<i>clrs</i> = <b>getColorPalette</b>(<i>name, ncolors</i>);</td>
</tr>
<tr>
<td><b>getHSLPalette</b></td><td>Create a set of evenly spaced colors in HSL hue space.</td><td><i>clrs</i> = <b>getHSLPalette</b>(<i>ncolors, h, s, l</i>);</td>
</tr>
<tr>
<td><b>getHSLuvPalette</b></td><td>Create a set of evenly spaced circular hues in the HSLuv system.</td><td><i>clrs</i> = <b>getHSLuvPalette</b>(<i>ncolors, h, s, l</i>);<br></td>
</tr>
<tr>
<td><b>blendColorPalette</b></td><td>Create a new palette that blends between a list of colors.</td><td><i>clrs</i> = <b>blendColorPalette</b>(<i>colors, ncolors</i>);<br></td>
</tr>
</table>
<p>As an example, let's look at getting the first three colors from the <a href="http://colorbrewer2.org/#type=sequential&amp;scheme=BuGn&amp;n=3">ColorBrewer</a> <i>Dark2</i> color palette:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Get the first 3 colors from the ColorBrewer 'Dark2' palette
clrs = getColorPalette("Dark2", 3);</code></pre>
<p>The resulting colors are:</p>
<table align="center" style="width: 50%">
  <colgroup>
       <col span="1" style="width: 25%;">
       <col span="1" style="width: 25%;">
    </colgroup>
<tr>
<td>#1b9e77</td><td style="background-color: #1b9e77;"></td>
</tr>
<tr>
<td>#d95f02</td><td style="background-color: #d95f02;"></td>
</tr>
<tr>
<td>#7570b3</td><td style="background-color: #7570b3;"></td>
</tr>
</table>
<p>Once the color palette is set, we can use these colors in GAUSS graphs for the line, background, or bar colors. </p>
<p>For example, to use our color palette to plot different colors for each series in a bar graph we would use <code>plotSetFill</code> to change the color assignment in our <code>plotControl</code> structure:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Declare plotControl structure
struct plotControl myPlot;

// Initialize plotControl structure
myPlot = plotGetDefaults("bar");

// Set all bars to have a solid fill with the colors
// assigned to 'clrs' in the previous code box
textures = 1;
plotSetFill(&amp;myPlot, textures, 1, clrs);

// Create data
x = seqa(1, 1, 5);
y1 = { 1.5, 2, 3, 0.5, 1 };
y2 = { 3, 6.7, 8, 2, 0.49 };
y3 = { 2, 3.4, 2.4, 1, 3 };

// Draw bar graph
plotBar(myPlot, x, y1~y2~y3);</code></pre>
<div id="attachment_19791" style="width: 810px" class="wp-caption aligncenter"><a href="https://www.aptech.com/wp-content/uploads/2019/03/five-graph-hacks-bar-dark2.png"><img aria-describedby="caption-attachment-19791" decoding="async" fetchpriority="high" src="https://www.aptech.com/wp-content/uploads/2019/03/five-graph-hacks-bar-dark2.png" alt="Bar graph with Colorbrewer color palette." width="400" height="250" class="aligncenter size-full wp-image-19791" /></a><p id="caption-attachment-19791" class="wp-caption-text"><center> Bar graph with Colorbrewer 'Dark2' color palette.</center></p></div>

<h2 id="controlling-graph-exports">Controlling graph exports</h2>
<p>Our second hack, the GAUSS <code>plotSave</code> procedure, is a handy tool which allows us to control the file type, size, and dots per inch (DPI) of exported graphs in a single command.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSave(filename, size); 
plotSave(filename, size, units);
plotSave(filename, size, units dpi);</code></pre>
<p>The procedure is easy to use and has two required inputs and two optional inputs:</p>
<hr>
<dl>
<dt>filename</dt>
<dd>String, name of the file to create with a file type extension. Available file extensions include: <i>.jpg, .plot, .png, .pdf, .svg, .tiff</i>.</dd>
<dt>size</dt>
<dd>2x1 vector, dimensions of the saved graph in specified units. The default unit is centimeters.</dd>
<dt>units</dt>
<dd>Optional input, String, type of units dimension is specified in. Valid options include:<br/>
    &quot;cm&quot; Centimeters (Default)<br />
    &quot;mm&quot; Millimeters<br />
    &quot;in&quot; Inches<br />
    &quot;px&quot; Pixels  </dd>
<dt>dpi</dt>
<dd>Optional input, scalar, requested dots per inch when saving file. Defaults to current system DPI. <i>dpi</i> determines the number of pixels rendered when saving a file in terms of physical dimensions (cm, mm, in).
<hr></dd>
</dl>
<p>For example, if a publisher requests a 640 x 480 pixel <i>.png</i> plot, we specify:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Save the graph as a 640 wide by 480 tall PNG file
plotSave("mygraph.png", 640 | 480, "px");</code></pre>
<p>However, if we need an 11 x 8.5 inch PDF at 300 DPI for a flyer, we specify:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Save the graph as a 11 x 8.5 inch PDF at 300 DPI
plotSave("mygraph.pdf", 11 | 8.5, "in", 300);</code></pre>
<p>There are some helpful things to note about the <code>plotSave</code> procedure:</p>
<ul>
<li>The <i>size</i> input is a <b>required</b> input for all file types except <i>.plot</i> files.  </li>
<li>The <i>unit</i> input is ignored if the file is a <i>.plot</i> file. </li>
<li>The <i>dpi</i> input determines the number of pixels rendered when saving a file in terms of physical dimensions (cm, mm, in). Specifying the <i>dpi</i> parameter has no effect if the specified units are pixels (px). </li>
</ul>
<h2 id="changing-the-plot-canvas-size">Changing the plot canvas size</h2>
<p>There may be times when we want to see how a graph looks at a different size before we export it. This can be easily done with our next tool, <code>plotCanvasSize</code>. </p>
<p>The GAUSS procedure <code>plotCanvasSize</code> adjusts plot canvas sizes programmatically based on specifications in <a href="https://github.com/aptech/gauss-plot-library/blob/master/images/grid-plot-adjusted-canvas.jpeg">centimeters, millimeters, inches or pixels</a>. </p>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/03/gblog-plot-polarrose-fullui.png"><img src="https://www.aptech.com/wp-content/uploads/2019/03/gblog-plot-polarrose-fullui.png" alt="Programmatically controlled size of GAUSS graph." width="2294" height="1400" class="aligncenter size-full wp-image-19757" /></a></p>
<p>To produce our graph on a 750 px by 350 px canvas, as shown above, we place the call to <code>plotCanvasSize</code> prior to calling our graphic procedure:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Make this call before your plot to set the graph canvas
** to 750 px by 530 px as shown in the image above
*/
plotCanvasSize("px", 750|530);</code></pre>
<p>When we are ready to go back to the default canvas size when simply tell GAUSS to &quot;fill&quot; the plot canvas:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Go back to factory canvas size
plotCanvasSize("fill");</code></pre>
<div class="alert alert-info" role="alert"><strong>Tip:</strong> Sometimes when making grid plot, the individual plot size becomes so small that the x-axis labels are cut off. <a href="https://github.com/aptech/gauss-plot-library/blob/master/docs/grid-plot-adjusted-canvas.md">Increasing the plot canvas size</a> will fix this problem.  </div>
<h2 id="annotating-graphs-with-shapes-text-boxes-and-lines">Annotating graphs with shapes, text boxes, and lines</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/03/gblog-hist-bootmean.png"><img src="https://www.aptech.com/wp-content/uploads/2019/03/gblog-hist-bootmean.png" alt="GAUSS annotated graph." width="640" height="360" class="aligncenter size-full wp-image-19755" /></a></p>
<p>Annotations make graphs more professional, more readable and easier to interpret. There are three easy-to-use functions for adding annotations to any existing GAUSS plot:</p>
<table style="width: 100%">
    <colgroup>
       <col span="1" style="width: 15%;">
       <col span="1" style="width: 30%;">
       <col span="1" style="width: 55%;">
    </colgroup>
<tr>
<td><b>Procedure</b></td><td><b>Description</b></td><td><b>Format</b></td>
</tr>
<tr style="background-color: #F5F5F5;">
<td><b>plotAddArrow</b></td><td>Adds an arrow to an existing graph.</td><td><b>plotAddArrow</b>( <i>[myAnnotation,] x_start, y_start, x_end, y_end, head_size</i>); </td>
</tr>
<tr>
<td><b>plotAddShape</b></td><td>Adds an arrow, line, ellipse or rectangle to an existing graph.</td><td><b>plotAddShape</b>(<i>[myAnnotation,] which_shape, x_start, y_start, x_end, y_end</i>); </td>
</tr>
<tr style="background-color: #F5F5F5;">
<td><b>plotAddTextbox</b></td><td>Adds a textbox to an existing graph.</td><td><b>plotAddTextbox</b>(<i>[myAnnotation,] text, x_start, y_start</i>);</td>
</tr>
</table>
<p>To create annotations there are a few key things to remember:</p>
<ul>
<li>The location of an annotation is specified using starting, and when applicable ending, <i>x</i> and <i>y</i> coordinates.  </li>
<li>We can use default settings for annotations or we can customize the appearance using the optional <code>plotAnnotation</code> structure.  </li>
<li>If we plan on using our annotations often and want to use the same styling, instead of going through multiple steps to set up the style each time, we can create a simple procedure to do the set up:</li>
</ul>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Add the procedure below to your user library
** and you will only need one line for all the settings
*/
plotAddTextbox(grayTextSettings(), "My customized text box", 0.15, 0.2);

proc (1) = grayTextSettings();
    struct plotAnnotation mytextbox;

    mytextbox = annotationGetDefaults();
    annotationSetBkd(&amp;mytextbox, "#DDDDDD", 0.3);
    annotationSetFont(&amp;mytextbox, "times", 18, "#555555");
    annotationSetLineThickness(&amp;mytextbox, 2);
    annotationSetLineColor(&amp;mytextbox, "#555555");
    retp(mytextbox);
endp;</code></pre>
<h2 id="using-latex-for-gauss-legends-label-and-text-boxes">Using LaTeX for GAUSS legends, label and text boxes</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/03/gblog-trigonometric-plot-latex.png"><img src="https://www.aptech.com/wp-content/uploads/2019/03/gblog-trigonometric-plot-latex.png" alt="GAUSS graph with LaTeX equations." width="900" height="500" class="aligncenter size-full wp-image-19758" /></a></p>
<p><a href="https://www.latex-project.org/">LaTeX</a> is a powerful tool for generating scientific and technical documents because of its flexibility and ability to transcribe mathematical functions. GAUSS allows users to use the MathJax library for the interpretation of a <a href="http://docs.mathjax.org/en/v2.7-latest/tex.html#supported-latex-commands"">wide variety of LaTeX commands</a>. </p>
<p>To use LaTeX, we must first set the GAUSS text interpreter to ‘latex’ using the <code>plotSetTextInterpreter</code> procedure. This procedure requires three inputs:</p>
<hr>
<dl>
<dt>&amp;myPlot</dt>
<dd>A plotControl structure pointer.</dd>
<dt>interpreter</dt>
<dd>String, &quot;html&quot;, &quot;plain&quot;, &quot;latex&quot;.</dd>
<dt>location</dt>
<dd>String, &quot;all&quot;, &quot;legend&quot;, &quot;title&quot; or &quot;axes&quot;. Default is &quot;all&quot;.
</hr></dd>
</dl>
<p>For example, let's use <a href="https://github.com/aptech/gauss-plot-library/blob/master/docs/xy_latex.md">LaTeX for our legend, axes, and title</a>:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Declare plotControl structure
struct plotControl myPlot;

// Initialize plotControl structure
myPlot = plotGetDefaults("xy");

// Set up text interpreter
plotSetTextInterpreter(&amp;myPlot, "latex", "all");</code></pre>
<p>We can now use LaTeX syntax for labeling our graph:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set up legend in LateX format
string legend_string = {
"y_1 = \\cos{(x)}",
"y_2 = \\sin{(\\frac{x}{2})} = \\pm \\sqrt{\\frac{1-\\cos{(x)}}{2}}",
"y_3 = \\cos{(\\frac{x}{2})} = \\pm \\sqrt{\\frac{1+\\cos{(x)}}{2}}" };

plotSetLegend(&amp;myPlot, legend_string, "bottom right inside",1);</code></pre>
<p>There are a few things to remember when using LaTeX in GAUSS:</p>
<ol>
<li>Since backslashes are used for escape sequences in strings, you must use double backslashes.  </li>
<li>Strings interpreted as LaTeX are automatically in ‘inline equation mode’. Therefore to add regular text, you must enclose the text inside of  \text{ }. For example:
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Since LaTeX does not respect spaces inside of equations
** add a space after 'equation is' inside of the text section
*/
"\\text{The equation is } \\alpha + \\beta X"</code></pre></li>
<li>Text inside of a '\text{}' section will use the font set by the user as it would if the text interpreter were set to plain or HTML.
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** 'Posterior distribution' will be in Times 24 point font
** The greek lambda will be proportional in size to Times 24, but will be in TeX font
*/
plotSetTitle(&amp;myPlot, "\\text{Posterior distribution of  } \\lambda_1", "Times", 24);</code></pre></li>
</ol>
<h3 id="conclusion">Conclusion</h3>
<p>GAUSS graphics tools have been created with the end goal of generating publication quality graphs. In this blog we highlight five advanced hacks for raising the bar on your custom GAUSS graphics:</p>
<ol>
<li>Using <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.413.9004&amp;rep=rep1&amp;type=pdf">HSL</a>, <a href="http://www.hsluv.org/">HSLuv</a>, and <a href="http://colorbrewer2.org/#type=sequential&amp;scheme=BuGn&amp;n=3">Colorbrewer</a> color palettes.</li>
<li>Controlling graph exports.</li>
<li>Changing the plot canvas size.</li>
<li>Annotating graphs with shapes, text boxes, and lines.</li>
<li>Using LaTeX for GAUSS legends, labels and text boxes.</li>
</ol>
<p>For more tips and graph examples, please see our <a href="https://github.com/aptech/gauss-plot-library">GAUSS plot library</a>.</p>
<p></p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Graph high frequency Forex data</title>
		<link>https://www.aptech.com/blog/graph-high-frequency-forex-data/</link>
					<comments>https://www.aptech.com/blog/graph-high-frequency-forex-data/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 16 Nov 2018 15:44:30 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Time Series]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=18334</guid>

					<description><![CDATA[Last week we learned <a href="https://www.aptech.com/blog/reading-dates-and-times-in-gauss/">how to use the `date` keyword</a> to load dates into GAUSS. Today, we extend our analysis of time series data to plot high-frequency Forex data.]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Last week we learned <a href="https://www.aptech.com/blog/reading-dates-and-times-in-gauss/">how to use the <code>date</code> keyword</a> to load dates into GAUSS. Today, we will plot some high-frequency Forex data.</p>
<h2 id="the-data">The data</h2>
<p>Today's dataset (<a href="https://www.aptech.com/wp-content/uploads/2018/11/usdcad_tick.csv">usdcad_tick.csv</a>) contains tick data for a little over 30,000 observations of the bid price for the USD/CAD currency pair from January 2, 2018. </p>
<p>This file has two variables:</p>
<ul>
<li><strong>timestamp</strong>: The time of the bid as a POSIX date/time (seconds since Jan 1, 1970).</li>
<li><strong>bid</strong>: The bid price.</li>
</ul>
<p>The first few observations of the file look like this:</p>
<pre>timestamp,bid
1514872801.247, 1.25372
1514872801.497, 1.25376
1514872801.747, 1.25373
1514872802.247, 1.25377
1514872802.497, 1.25377</pre>
<p>The fractional portion of the timestamp data represents nanoseconds.</p>
<h2 id="plottshf">plotTSHF</h2>
<p><a href="https://docs.aptech.com/gauss/plottshf.html"><code>plotTSHF</code></a> is a function which will draw graphs of irregularly spaced and high-frequency <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series data</a>. It has three required inputs:</p>
<hr>
<dl>
<dt>date_vec</dt>
<dd>Tx1 vector containing POSIX date/times for each observation.</dd>
<dt>label_unit</dt>
<dd>The unit to use for X-axis tick labels. Valid options include:</dd>
</dl>
<ul>
<li>milliseconds</li>
<li>seconds</li>
<li>minutes</li>
<li>hours</li>
<li>days</li>
<li>months</li>
<li>quarters</li>
<li>years</li>
</ul>
<dl>
<dt>y</dt>
<dd>Tx1 vector or TxP matrix containing the data to plot.</dd>
</dl>
<hr>
<h2 id="basic-plot">Basic plot</h2>
<p>We can plot our dataset with the following code:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load all observations of both variables
fname = "usdcad_tick.csv";
data = loadd(fname);

// Split variables into separate vectors
timevec = data[.,1];
bid = data[.,2];

// Plot data
plotTSHF(timevec, "hours", bid);</code></pre>
<p>and we will see a graph that looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2018/11/gblog-plottshf-11162018-1.png"><img src="https://www.aptech.com/wp-content/uploads/2018/11/gblog-plottshf-11162018-1.png" alt="Graph of high-frequency USD/CAD currency pairs." width="600" height="300" class="aligncenter size-full wp-image-18371" /></a></p>
<h3 id="label_unit">label_unit</h3>
<p>Most of the code we used to create this graph should be fairly straightforward, with the possible exception of the <code>label_unit</code> input.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotTSHF(timevec, "hours", bid);</code></pre>
<p>In the above line of code, the <code>label_unit</code> is <code>"hours"</code>. This tells GAUSS that we would like X-tick labels to be set at even hours.</p>
<p>If we used <code>"days"</code> we would not see any X-tick labels. This is because our data is from 06:00-18:00 on the same day. Since the <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series data</a> does not cross from one day to another, the graph does not contain the start of a day at which to place the tick label.</p>
<h2 id="customize-tick-labels">Customize tick labels</h2>
<p>Now we will use <a href="https://www.aptech.com/resources/tutorials/time-series-plots/#basic-ts-tick-interval">plotSetXTicInterval</a> to set the X-ticks to appear every 60 minutes, starting at 06:30.</p>
<div class="alert alert-info" role="alert">Not sure how to use a <code>plotControl</code> structure? <a href="https://www.aptech.com/resources/tutorials/basic-graph-with-programmatic-customization/">Click here for help</a>.</div>
<p>To accomplish this, we will have to take the following steps:</p>
<ol>
<li>Set the <code>label_unit</code> passed to <code>plotTSHF</code> to <code>"minutes"</code>.
<ul>
<li>This step tells <code>plotTSHF</code> to place the X-tick labels at even minutes.</li>
</ul></li>
<li>Set the <code>tick_interval</code> input to <code>plotSetXTicInterval</code> to be 60.
<ul>
<li>Since the <code>tick_interval</code> is in terms of the <code>plotTSHF</code> <code>label_unit</code>, setting <code>tick_interval</code> to 60 will set the X-ticks to be placed every 60 minutes.</li>
</ul></li>
<li>Set the <code>first_labeled</code> input to <code>plotSetXTicInterval</code> to be a POSIX date which equals Jan 2, 2018 06:30.
<ul>
<li>Since <code>plotTSHF</code> uses only POSIX date/times, we must specify the first X-tick to label as a POSIX date/time.</li>
</ul></li>
</ol>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load all observations of both variables
fname = "usdcad_tick.csv";
data = loadd(fname);

// Split variables into separate vectors
timevec = data[.,1];
bid = data[.,2];

// Declare 'myPlot' to be a plotControl struct
// and fill with default values
struct plotControl myPlot;
myPlot = plotGetDefaults("xy");

// Convert the DT Scalar date to POSIX
// YYYY MO DD HH MI SS
// 2018 01 02 06 30 00
first_lbl = dttoposix(2018010206300);

// Draw X-tick labels every 60 minutes,
// starting at Jan 2, 2018 at 06:30
plotSetXTicInterval(&amp;myPlot, 60, first_lbl);

// Plot data (notice we pass in the plotControl struct)
plotTSHF(myPlot, timevec, "minutes", bid);</code></pre>
<p>The above code will create a graph like shown below.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2018/11/gblog-plottshf-11162018-2.png"><img src="https://www.aptech.com/wp-content/uploads/2018/11/gblog-plottshf-11162018-2.png" alt="Graph of high-frequency USD/CAD currency pair data." width="600" height="300" class="aligncenter size-full wp-image-18372" /></a></p>
<h3 id="conclusions">Conclusions</h3>
<p>Congratulations! You have learned how to:</p>
<ol>
<li>Plot high-frequency <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series data</a> with <code>plotTSHF</code>, using POSIX date/times.</li>
<li>Customize the frequency and starting point of X-tick labels for <a href="https://www.aptech.com/resources/tutorials/time-series-plots/">time series graphs</a> using <code>plotTSHF</code>.</li>
</ol>
<p>Code and data from this blog can be found <a href="https://github.com/aptech/gauss_blog/tree/master/graphics/high-frequency-data-11.16.18">here</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/graph-high-frequency-forex-data/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
