<?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>#gauss22 &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/tag/gauss22/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Tue, 14 Dec 2021 18:57:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<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>
	</channel>
</rss>
