<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics</title><revhistory><revision><revnumber>15</revnumber><date>2015-05-02 18:42:40</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>14</revnumber><date>2015-05-02 18:34:25</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>13</revnumber><date>2015-05-01 11:55:13</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>12</revnumber><date>2015-05-01 11:53:22</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>11</revnumber><date>2015-05-01 11:50:17</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>10</revnumber><date>2015-05-01 11:49:43</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>9</revnumber><date>2015-05-01 11:46:59</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>8</revnumber><date>2015-05-01 11:39:57</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>7</revnumber><date>2015-05-01 11:33:40</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>6</revnumber><date>2015-05-01 11:31:15</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>5</revnumber><date>2015-05-01 11:26:14</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>4</revnumber><date>2015-05-01 11:05:40</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>3</revnumber><date>2015-05-01 11:03:33</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>2</revnumber><date>2015-05-01 10:58:18</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>1</revnumber><date>2015-05-01 10:55:21</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision></revhistory></articleinfo><section><title>The ggplot2 Package</title><itemizedlist><listitem><para>ggplot2 is - like lattice based on the grid graphics system (Paul Murrell) </para></listitem><listitem><para>graphics and parts of graphics are objects and they are manipulable </para></listitem></itemizedlist><section><title>Structure of a ggplot Object</title><para>begin with an empty object to see the structure: </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[po]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[()]]>
<![CDATA[> ]]><methodname><![CDATA[summary]]></methodname><![CDATA[(]]><methodname><![CDATA[po]]></methodname><![CDATA[)]]>
<methodname><![CDATA[data]]></methodname><![CDATA[: ]]><methodname><![CDATA[[x]]></methodname><methodname><![CDATA[]]]></methodname>
<methodname><![CDATA[faceting]]></methodname><![CDATA[: ]]><methodname><![CDATA[facet_null]]></methodname><![CDATA[()]]>
</programlisting><itemizedlist><listitem><para>what we see are empty place holders </para></listitem><listitem><para>when we use str() to explore the structure of the object we see that it is a list with length 9 </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[str]]></methodname><![CDATA[(]]><methodname><![CDATA[po]]></methodname><![CDATA[)]]>
<methodname><![CDATA[List]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ 9]]>
<![CDATA[  ]]><methodname><![CDATA[List]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ 9]]>
<![CDATA[  $ ]]><methodname><![CDATA[data]]></methodname><![CDATA[       : ]]><methodname><![CDATA[list]]></methodname><![CDATA[()]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[- ]]><methodname><![CDATA[attr]]></methodname><![CDATA[(*, ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[class"]]></phrase><![CDATA[)= ]]><methodname><![CDATA[chr]]></methodname><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[waiver"]]></phrase>
<![CDATA[  $ ]]><methodname><![CDATA[layers]]></methodname><![CDATA[     : ]]><methodname><![CDATA[list]]></methodname><![CDATA[()]]>
<![CDATA[  $ ]]><methodname><![CDATA[scales]]></methodname><![CDATA[     :]]><methodname><![CDATA[Reference]]></methodname><![CDATA[ ]]><methodname><![CDATA[class]]></methodname><![CDATA[ ]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[Scales']]></phrase><![CDATA[ ]]><methodname><![CDATA[[package]]></methodname><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggplot2"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><methodname><![CDATA[with]]></methodname><![CDATA[ 1 ]]><methodname><![CDATA[fields]]></methodname>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[$ ]]><methodname><![CDATA[scales]]></methodname><![CDATA[: ]]><symbol><![CDATA[NULL]]></symbol>
<![CDATA[  ]]><methodname><![CDATA[..and]]></methodname><![CDATA[ 21 ]]><methodname><![CDATA[methods]]></methodname><![CDATA[, ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[which]]></methodname><![CDATA[ 9 ]]><methodname><![CDATA[are]]></methodname><![CDATA[ ]]><methodname><![CDATA[possibly]]></methodname><![CDATA[ ]]><methodname><![CDATA[relevant]]></methodname><![CDATA[:]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[  ]]><methodname><![CDATA[add]]></methodname><![CDATA[, ]]><methodname><![CDATA[clone]]></methodname><![CDATA[, ]]><methodname><![CDATA[find]]></methodname><![CDATA[, ]]><methodname><![CDATA[get_scales]]></methodname><![CDATA[, ]]><methodname><![CDATA[has_scale]]></methodname><![CDATA[, ]]><methodname><![CDATA[initialize]]></methodname><![CDATA[, ]]><methodname><![CDATA[input]]></methodname><![CDATA[, ]]><methodname><![CDATA[n]]></methodname><![CDATA[,]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[  ]]><methodname><![CDATA[non_position_scales]]></methodname>
<![CDATA[  $ ]]><methodname><![CDATA[mapping]]></methodname><![CDATA[    : ]]><methodname><![CDATA[list]]></methodname><![CDATA[()]]>
<![CDATA[  $ ]]><methodname><![CDATA[theme]]></methodname><![CDATA[      : ]]><methodname><![CDATA[list]]></methodname><![CDATA[()]]>
<![CDATA[  $ ]]><methodname><![CDATA[coordinates]]></methodname><![CDATA[:]]><methodname><![CDATA[List]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ 1]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[$ ]]><methodname><![CDATA[limits]]></methodname><![CDATA[:]]><methodname><![CDATA[List]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ 2]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[ ]]><methodname><![CDATA[..]]></methodname><![CDATA[$ ]]><methodname><![CDATA[x]]></methodname><![CDATA[: ]]><symbol><![CDATA[NULL]]></symbol>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[ ]]><methodname><![CDATA[..]]></methodname><![CDATA[$ ]]><methodname><![CDATA[y]]></methodname><![CDATA[: ]]><symbol><![CDATA[NULL]]></symbol>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[- ]]><methodname><![CDATA[attr]]></methodname><![CDATA[(*, ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[class"]]></phrase><![CDATA[)= ]]><methodname><![CDATA[chr]]></methodname><![CDATA[ ]]><methodname><![CDATA[[1]]></methodname><![CDATA[:2]]><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[cartesian"]]></phrase><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[coord"]]></phrase>
<![CDATA[  $ ]]><methodname><![CDATA[facet]]></methodname><![CDATA[      :]]><methodname><![CDATA[List]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ 1]]>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[$ ]]><methodname><![CDATA[shrink]]></methodname><![CDATA[: ]]><methodname><![CDATA[logi]]></methodname><![CDATA[ ]]><symbol><![CDATA[TRUE]]></symbol>
<![CDATA[  ]]><methodname><![CDATA[..]]></methodname><![CDATA[- ]]><methodname><![CDATA[attr]]></methodname><![CDATA[(*, ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[class"]]></phrase><![CDATA[)= ]]><methodname><![CDATA[chr]]></methodname><![CDATA[ ]]><methodname><![CDATA[[1]]></methodname><![CDATA[:2]]><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[null"]]></phrase><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[facet"]]></phrase>
<![CDATA[  $ ]]><methodname><![CDATA[plot_env]]></methodname><![CDATA[   :<]]><methodname><![CDATA[environment]]></methodname><![CDATA[: ]]><methodname><![CDATA[R_GlobalEnv]]></methodname><![CDATA[>]]>
<![CDATA[  $ ]]><methodname><![CDATA[labels]]></methodname><![CDATA[     : ]]><methodname><![CDATA[list]]></methodname><![CDATA[()]]>
<![CDATA[  - ]]><methodname><![CDATA[attr]]></methodname><![CDATA[(*, ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[class"]]></phrase><![CDATA[)= ]]><methodname><![CDATA[chr]]></methodname><![CDATA[ ]]><methodname><![CDATA[[1]]></methodname><![CDATA[:2]]><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[gg"]]></phrase><![CDATA[ ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggplot"]]></phrase>
</programlisting></section><section><title>Structure of a ggplot Object</title><para>Now we fill this structure - first the three main steps: </para><itemizedlist><listitem><para>the first argument to ggplot is data </para></listitem><listitem><para>then specify what graphics shapes you are going to use to view the data (e.g. geom_line() or geom_point()). </para></listitem><listitem><para>specify what features (or aesthetics) will be used (e.g. what variables will determine x- and y-locations) with the aes() function </para></listitem><listitem><para>if these aesthetics are intented to be used in all layers it is more convenient to specify them in the ggplot object </para></listitem></itemizedlist></section><section><title>Feed the Object</title><itemizedlist><listitem><para>first we create a little sample data frame\small </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[x1]]></methodname><![CDATA[ <- 1:10; ]]><methodname><![CDATA[y1]]></methodname><![CDATA[ <- 1:10; ]]><methodname><![CDATA[z1]]></methodname><![CDATA[ <- 10:1]]>
<![CDATA[> ]]><methodname><![CDATA[l1]]></methodname><![CDATA[ <- ]]><symbol><![CDATA[LETTERS]]></symbol><methodname><![CDATA[[1]]></methodname><![CDATA[:10]]><methodname><![CDATA[]]]></methodname>
<![CDATA[> ]]><methodname><![CDATA[a]]></methodname><![CDATA[ <- 10; ]]><methodname><![CDATA[b]]></methodname><![CDATA[ <- (0:-9)/10:1]]>
<![CDATA[> ]]><methodname><![CDATA[ex]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[x1]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[y1]]></methodname><![CDATA[,]]><methodname><![CDATA[z]]></methodname><![CDATA[=]]><methodname><![CDATA[z1]]></methodname><![CDATA[,]]><methodname><![CDATA[l]]></methodname><![CDATA[=]]><methodname><![CDATA[l1]]></methodname><![CDATA[,]]><methodname><![CDATA[a]]></methodname><![CDATA[=]]><methodname><![CDATA[a]]></methodname><![CDATA[,]]><methodname><![CDATA[b]]></methodname><![CDATA[=]]><methodname><![CDATA[b]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ex]]></methodname>
<methodname><![CDATA[x]]></methodname><![CDATA[  ]]><methodname><![CDATA[y]]></methodname><![CDATA[  ]]><methodname><![CDATA[z]]></methodname><![CDATA[ ]]><methodname><![CDATA[l]]></methodname><![CDATA[  ]]><methodname><![CDATA[a]]></methodname><![CDATA[          ]]><methodname><![CDATA[b]]></methodname>
<![CDATA[1   1  1 10 ]]><methodname><![CDATA[A]]></methodname><![CDATA[ 10  0.0000000]]>
<![CDATA[2   2  2  9 ]]><methodname><![CDATA[B]]></methodname><![CDATA[ 10 -0.1111111]]>
<![CDATA[3   3  3  8 ]]><methodname><![CDATA[C]]></methodname><![CDATA[ 10 -0.2500000]]>
<![CDATA[4   4  4  7 ]]><methodname><![CDATA[D]]></methodname><![CDATA[ 10 -0.4285714]]>
<![CDATA[5   5  5  6 ]]><methodname><![CDATA[E]]></methodname><![CDATA[ 10 -0.6666667]]>
<![CDATA[6   6  6  5 ]]><token><![CDATA[F]]></token><![CDATA[ 10 -1.0000000]]>
<![CDATA[7   7  7  4 ]]><methodname><![CDATA[G]]></methodname><![CDATA[ 10 -1.5000000]]>
<![CDATA[8   8  8  3 ]]><methodname><![CDATA[H]]></methodname><![CDATA[ 10 -2.3333333]]>
<![CDATA[9   9  9  2 ]]><methodname><![CDATA[I]]></methodname><![CDATA[ 10 -4.0000000]]>
<![CDATA[10 10 10  1 ]]><methodname><![CDATA[J]]></methodname><![CDATA[ 10 -9.0000000]]>
</programlisting><itemizedlist><listitem><para>then we create a ggplot object containing the data and some standard aesthetics (here we define the x and the y positions) </para></listitem><listitem><para>add one or more geoms, we begin with  geom_point </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[po]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[ex]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[x1]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[y1]]></methodname><![CDATA[))]]>
<![CDATA[> ]]><methodname><![CDATA[summary]]></methodname><![CDATA[(]]><methodname><![CDATA[po]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[p1]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[po]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[()]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp1.pdf">ggp1.pdf</ulink> </para></section><section><title>Layers</title><itemizedlist><listitem><para>ggplot() creates an object - every &quot;+&quot; adds something to this object (change the object) </para></listitem><listitem><para>the default method of ggplot() is print(), which creates the plot </para></listitem><listitem><para>it is better to store the object - so you can change it (e.g. you can change the data frame) </para></listitem></itemizedlist></section><section><title>Layers</title><itemizedlist><listitem><para>so we add another layer, which adds a label to the points (use geom_text) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[p2]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[po]]></methodname><![CDATA[ +]]>
<![CDATA[+    ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[+        ]]><methodname><![CDATA[geom_text]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[label]]></methodname><![CDATA[=]]><methodname><![CDATA[l]]></methodname><![CDATA[), ]]><methodname><![CDATA[hjust]]></methodname><![CDATA[=1.1, ]]><methodname><![CDATA[vjust]]></methodname><![CDATA[=-0.2)]]>
<![CDATA[> ]]><methodname><![CDATA[p2]]></methodname>
</programlisting><itemizedlist><listitem><para>aes(label=l) maps the l variable to the label aesthetic, and hjust and vjust define where our labels are placed </para></listitem></itemizedlist><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/ggp2.pdf#">ggp2.pdf</ulink> </para></section><section><title>Layers</title><itemizedlist><listitem><para>imagine you have worked a little time on a plot - and then you detect a mistake in your data, so the <emphasis>real</emphasis> data frame looks different </para></listitem><listitem><para>so you can replace the old, wrong data by the new  data (using %+%) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><lineannotation><![CDATA[## the new data]]></lineannotation>
<![CDATA[> ]]><methodname><![CDATA[ex2]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[x1]]></methodname><![CDATA[=]]><methodname><![CDATA[sample]]></methodname><![CDATA[(1:20),]]>
<![CDATA[+                   ]]><methodname><![CDATA[y1]]></methodname><![CDATA[=]]><methodname><![CDATA[sample]]></methodname><![CDATA[(1:10),]]>
<![CDATA[+                   ]]><methodname><![CDATA[l]]></methodname><![CDATA[=]]><symbol><![CDATA[letters]]></symbol><methodname><![CDATA[[1]]></methodname><![CDATA[:20]]><methodname><![CDATA[]]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[ex2]]></methodname><![CDATA[,10)]]>
<methodname><![CDATA[x1]]></methodname><![CDATA[ ]]><methodname><![CDATA[y1]]></methodname><![CDATA[ ]]><methodname><![CDATA[l]]></methodname>
<![CDATA[1   3  6 ]]><methodname><![CDATA[a]]></methodname>
<![CDATA[2   6  2 ]]><methodname><![CDATA[b]]></methodname>
<![CDATA[3  14  1 ]]><methodname><![CDATA[c]]></methodname>
<![CDATA[4  19 10 ]]><methodname><![CDATA[d]]></methodname>
<![CDATA[5  12  4 ]]><methodname><![CDATA[e]]></methodname>
<![CDATA[6  15  8 ]]><methodname><![CDATA[f]]></methodname>
<![CDATA[7  20  5 ]]><methodname><![CDATA[g]]></methodname>
<![CDATA[8  17  7 ]]><methodname><![CDATA[h]]></methodname>
<![CDATA[9  13  3 ]]><methodname><![CDATA[i]]></methodname>
<![CDATA[10 16  9 ]]><methodname><![CDATA[j]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp3.pdf">ggp3.pdf</ulink> </para></section><section><title>Layers</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[p2]]></methodname><![CDATA[ %+% ]]><methodname><![CDATA[ex2]]></methodname>
</programlisting></section><section><title>Layers</title><itemizedlist><listitem><para>by using the line geom you can join the points (we use the new data) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[pn]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[p]]></methodname><![CDATA[ %+% ]]><methodname><![CDATA[ex2]]></methodname><![CDATA[ ]]><lineannotation><![CDATA[## replace data in p]]></lineannotation>
<![CDATA[> ]]><methodname><![CDATA[pn]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_line]]></methodname><![CDATA[()]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp4.pdf">ggp4.pdf</ulink> </para></section><section><title>Layers</title><itemizedlist><listitem><para>you can also join the points in the order of the data fram by using the path geom instead\footnotesize </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[my.text]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[geom_text]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[label]]></methodname><![CDATA[=]]><methodname><![CDATA[l]]></methodname><![CDATA[),]]>
<![CDATA[+                          ]]><methodname><![CDATA[hjust]]></methodname><![CDATA[=1.1,]]>
<![CDATA[+                          ]]><methodname><![CDATA[vjust]]></methodname><![CDATA[=-0.2)]]>
<![CDATA[> ]]><methodname><![CDATA[pn]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_path]]></methodname><![CDATA[() + ]]><methodname><![CDATA[my.text]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp5.pdf">ggp5.pdf</ulink> </para></section><section><title>Layers</title><para>Adding extra lines: </para><itemizedlist><listitem><para>there are three geoms: abline, vline, hline </para></listitem><listitem><para>abline adds one or more lines with specified slope and intercept to the plot\footnotesize </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><lineannotation><![CDATA[## one line]]></lineannotation>
<![CDATA[> ]]><methodname><![CDATA[p]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_abline]]></methodname><![CDATA[(]]><methodname><![CDATA[intercept]]></methodname><![CDATA[=10,]]><methodname><![CDATA[slope]]></methodname><![CDATA[=-1,]]>
<![CDATA[+                          ]]><methodname><![CDATA[colour]]></methodname><![CDATA[=]]><methodname><![CDATA[rgb]]></methodname><![CDATA[(.5,.5,.9))]]>
<![CDATA[> ]]><lineannotation><![CDATA[## two lines]]></lineannotation>
<![CDATA[> ]]><methodname><![CDATA[p]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_abline]]></methodname><![CDATA[(]]><methodname><![CDATA[intercept]]></methodname><![CDATA[=]]><methodname><![CDATA[c]]></methodname><![CDATA[(10,9),]]><methodname><![CDATA[slope]]></methodname><![CDATA[=]]><methodname><![CDATA[c]]></methodname><![CDATA[(-1,-2),]]>
<![CDATA[+                              ]]><methodname><![CDATA[colour]]></methodname><![CDATA[=]]><methodname><![CDATA[rgb]]></methodname><![CDATA[(.5,.5,.9))]]>
<![CDATA[> ]]><methodname><![CDATA[more]]></methodname><![CDATA[ ]]><methodname><![CDATA[lines]]></methodname>
<![CDATA[> ]]><methodname><![CDATA[p]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_abline]]></methodname><![CDATA[(]]><methodname><![CDATA[intercept]]></methodname><![CDATA[=10:1,]]><methodname><![CDATA[slope]]></methodname><![CDATA[=-(10:1)/10,]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp6.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp6.png" width="800"/></imageobject><textobject><phrase>attachment:ggp6.png</phrase></textobject></inlinemediaobject></ulink>  </para></section><section><title>Layers</title><itemizedlist><listitem><para>adding lines referring to the data frame </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[p1]]></methodname><![CDATA[ +]]>
<![CDATA[+   ]]><methodname><![CDATA[geom_abline]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[slope]]></methodname><![CDATA[=]]><methodname><![CDATA[b]]></methodname><![CDATA[,]]><methodname><![CDATA[intercept]]></methodname><![CDATA[=]]><methodname><![CDATA[a]]></methodname><![CDATA[,]]><methodname><![CDATA[colour]]></methodname><![CDATA[=]]><methodname><![CDATA[x1]]></methodname><![CDATA[)) +]]>
<![CDATA[+   ]]><methodname><![CDATA[scale_x_continuous]]></methodname><![CDATA[(]]><methodname><![CDATA[limits]]></methodname><![CDATA[=]]><methodname><![CDATA[c]]></methodname><![CDATA[(0,10))]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp7.pdf">ggp7.pdf</ulink> </para></section><section><title>Layers</title><itemizedlist><listitem><para>the same works for the hline and the vline geom which add horizonal and vertical line(s) </para></listitem><listitem><para>argument: yintercept, xintercept respectively </para></listitem><listitem><para>setting and mapping are possible </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[p1]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_hline]]></methodname><![CDATA[(]]><methodname><![CDATA[yintercept]]></methodname><![CDATA[=1:10)]]>
<![CDATA[> ]]><methodname><![CDATA[p1]]></methodname><![CDATA[ + ]]><methodname><![CDATA[geom_hline]]></methodname><![CDATA[(]]><methodname><![CDATA[yintercept]]></methodname><![CDATA[=1:10) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_vline]]></methodname><![CDATA[(]]><methodname><![CDATA[xintercept]]></methodname><![CDATA[=1:10)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp8.pdf">ggp8.pdf</ulink> </para></section><section><title>Other Common Layers</title><itemizedlist><listitem><para>some other layers for 1 continuous variable: </para><itemizedlist><listitem><para>geom_boxplot() </para></listitem><listitem><para>geom_histogram() </para></listitem><listitem><para>geom_density() </para></listitem></itemizedlist></listitem><listitem><para>some other layers for 1 discrete variable: </para><itemizedlist><listitem><para>geom_bar() </para></listitem></itemizedlist></listitem><listitem><para>some other layers for 2 or more continuous variables: </para><itemizedlist><listitem><para>geom_smooth() </para></listitem><listitem><para>geom_density2d() </para></listitem><listitem><para>geom_contour() </para></listitem><listitem><para>geom_quantile() </para></listitem></itemizedlist></listitem></itemizedlist></section><section><title>Exercises</title><itemizedlist><listitem><para>use our data frame or load it: load(&quot;20150310data.rdata&quot;) </para></listitem><listitem><para>create a new variable EC1 containing the first 2 letters of the Event.Code column, use the function str_sub() from the stringr package (type ?str_sub  to get help) </para></listitem></itemizedlist><section><title>Solutions</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[EC1]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[factor]]></methodname><![CDATA[(]]><methodname><![CDATA[str_sub]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Event.Code]]></methodname><![CDATA[,1,2))]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[)]]>
<methodname><![CDATA[Subject]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sex]]></methodname><![CDATA[ ]]><methodname><![CDATA[Age_PRETEST]]></methodname><![CDATA[ ]]><methodname><![CDATA[Trial]]></methodname><![CDATA[ ]]><methodname><![CDATA[Event.Type]]></methodname><![CDATA[ ]]><methodname><![CDATA[Code]]></methodname><![CDATA[   ]]><methodname><![CDATA[Time]]></methodname><![CDATA[ ]]><methodname><![CDATA[TTime]]></methodname><![CDATA[ ]]><methodname><![CDATA[Uncertainty]]></methodname>
<![CDATA[1       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11     7   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    2 103745  2575           1]]>
<![CDATA[2       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11    12   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    2 156493  2737           1]]>
<![CDATA[3       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11    17   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    2 214772  6630           1]]>
<![CDATA[4       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11    22   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    1 262086  5957           1]]>
<![CDATA[5       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11    27   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    2 302589   272           1]]>
<![CDATA[6       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11    32   ]]><methodname><![CDATA[Response]]></methodname><![CDATA[    1 352703  7197           1]]>
<methodname><![CDATA[Duration]]></methodname><![CDATA[ ]]><methodname><![CDATA[Uncertainty.1]]></methodname><![CDATA[ ]]><methodname><![CDATA[ReqTime]]></methodname><![CDATA[ ]]><methodname><![CDATA[ReqDur]]></methodname><![CDATA[ ]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[ ]]><methodname><![CDATA[Pair.Index]]></methodname><![CDATA[    ]]><methodname><![CDATA[Type]]></methodname><![CDATA[ ]]><methodname><![CDATA[Event.Code]]></methodname>
<![CDATA[1     2599             3       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[       ]]><methodname><![CDATA[hit]]></methodname><![CDATA[          7 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[RO26.jpg]]></methodname>
<![CDATA[2     2800             2       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[ ]]><methodname><![CDATA[incorrect]]></methodname><![CDATA[         12 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[RO19.jpg]]></methodname>
<![CDATA[3     6798             2       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[       ]]><methodname><![CDATA[hit]]></methodname><![CDATA[         17 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[RS23.jpg]]></methodname>
<![CDATA[4     5999             2       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[ ]]><methodname><![CDATA[incorrect]]></methodname><![CDATA[         22 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[OF22.jpg]]></methodname>
<![CDATA[5      400             2       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[       ]]><methodname><![CDATA[hit]]></methodname><![CDATA[         27 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[AT08.jpg]]></methodname>
<![CDATA[6     7398             2       0   ]]><methodname><![CDATA[next]]></methodname><![CDATA[       ]]><methodname><![CDATA[hit]]></methodname><![CDATA[         32 ]]><methodname><![CDATA[Picture]]></methodname><![CDATA[   ]]><methodname><![CDATA[AT30.jpg]]></methodname>
<methodname><![CDATA[testid]]></methodname><![CDATA[ ]]><methodname><![CDATA[EC1]]></methodname>
<![CDATA[1  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[RO]]></methodname>
<![CDATA[2  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[RO]]></methodname>
<![CDATA[3  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[RS]]></methodname>
<![CDATA[4  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[OF]]></methodname>
<![CDATA[5  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[AT]]></methodname>
<![CDATA[6  ]]><methodname><![CDATA[test2]]></methodname><![CDATA[  ]]><methodname><![CDATA[AT]]></methodname>
</programlisting></section></section><section><title>Exercises II</title><para>Create the five plots and save them into a file.  </para><itemizedlist><listitem><para>create a plot using ggplot, map the variable EC1 to x and use geom_bar()  </para></listitem><listitem><para>now to the plot again, but add another aesthetic: fill (colour of the filling); map fill to Stim.Type  </para></listitem><listitem><para>add the position argument to geom_bar(), set it to &quot;fill&quot;  </para></listitem><listitem><para>now add facet_wrap(~testid) to show the same graph per time  </para></listitem><listitem><para>make a graph facetted per child showing stacked hit/incorrect bars with time on the x axis </para></listitem></itemizedlist><section><title>solutions</title><itemizedlist><listitem><para>create a plot using ggplot, map the variable EC1 to x and use geom_bar() </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[()]]>
<![CDATA[>]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot1.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot1.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot1.png" width="800"/></imageobject><textobject><phrase>attachment:plot1.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>now to the plot again, but add another aesthetic: fill (colour of the filling); map fill to Stim.Type </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[()]]>
<![CDATA[>]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot2.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot1.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot2.png" width="800"/></imageobject><textobject><phrase>attachment:plot1.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>add the position argument to geom_bar(), set it to &quot;fill&quot; </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[)]]>
<![CDATA[>]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot3.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot3.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot3.png" width="800"/></imageobject><textobject><phrase>attachment:plot3.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>now add facet_wrap(~testid) to show the same graph per time </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[)]]>
<![CDATA[>]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot4.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot4.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot4.png" width="800"/></imageobject><textobject><phrase>attachment:plot4.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>now add facet_wrap(~testid) to show the same graph per time </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[scales]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[free"]]></phrase><![CDATA[)]]>
<![CDATA[>]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot4a.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot4a.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot4a.png" width="800"/></imageobject><textobject><phrase>attachment:plot4a.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>make a graph facetted per child showing stacked hit/incorrect bars with time on the x axis </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~ ]]><methodname><![CDATA[Subject]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[plot5.png"]]></phrase><![CDATA[)]]>
<methodname><![CDATA[Saving]]></methodname><![CDATA[ 16 ]]><methodname><![CDATA[x]]></methodname><![CDATA[ 9.13 ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[image]]></methodname>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot5.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=plot5.png" width="800"/></imageobject><textobject><phrase>attachment:plot5.png</phrase></textobject></inlinemediaobject></ulink> </para></section></section><section><title>Scales</title><para>What if we want to change the colours? </para><itemizedlist><listitem><para>this leads to another important type of component not yet mentioned </para></listitem><listitem><para>if you map a variable to a aesthetic is these done in a default way, in this case some reddish colour is mapped to hit while light blue is mapped to incorrect; in addition a discrete range of colours is automatically used </para></listitem><listitem><para>these rules of mapping are called scales </para></listitem><listitem><para>different type of scales exists for the axes, colours, shapes etc, some of them exists in discrete and continuous versions, some in just one of them (in general one can say, everytime there can be a legend there is a scale) </para></listitem><listitem><para>the name convention: scale_aesthetic_specification. for example scale_x_discrete for customizing a discrete x axis (e.g. in barplots) </para></listitem></itemizedlist></section><section><title>Changing a Scale</title><itemizedlist><listitem><para>to change our discrete colour scale for the filling we type \footnotesize </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[scales]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[free"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_fill_manual]]></methodname><![CDATA[(]]><methodname><![CDATA[values]]></methodname><![CDATA[=]]><methodname><![CDATA[c]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[forestgreen"]]></phrase><![CDATA[,]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[firebrick"]]></phrase><![CDATA[))]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp10.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp10.png" width="800"/></imageobject><textobject><phrase>attachment:ggp10.png</phrase></textobject></inlinemediaobject></ulink> </para><para>There are other ways to customize a discrete colour/fill scales </para><itemizedlist><listitem><para>scale_colour_grey() </para></listitem><listitem><para>scale_colour_hue() </para></listitem><listitem><para>scale_colour_brewer() </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[scales]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[free"]]></phrase><![CDATA[) +]]>
<![CDATA[+         ]]><methodname><![CDATA[scale_fill_grey]]></methodname><![CDATA[()]]>
<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[scales]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[free"]]></phrase><![CDATA[) +]]>
<![CDATA[+         ]]><methodname><![CDATA[scale_fill_hue]]></methodname><![CDATA[(]]><methodname><![CDATA[h]]></methodname><![CDATA[=]]><methodname><![CDATA[c]]></methodname><![CDATA[(180,360))]]>
<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[EC1]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_bar]]></methodname><![CDATA[(]]><methodname><![CDATA[position]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[fill"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[scales]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[free"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_fill_brewer]]></methodname><![CDATA[(]]><methodname><![CDATA[type]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[div"]]></phrase><![CDATA[,]]><methodname><![CDATA[palette]]></methodname><![CDATA[ = 2)]]>
</programlisting></section><section><title>Continuous Scales</title><para>Not only colour scales are modifiable </para><itemizedlist><listitem><para>here scale_aesthetic_specification becomes  scale_x_continuous() or  scale_y_continuous() </para></listitem><listitem><para>to transform a axis we can use the trans arg </para></listitem><listitem><para>we now create a scatter plot with Trial on the x-axis and TTime on the y-axis </para></listitem><listitem><para>the respective geom is geom_point() </para></listitem><listitem><para>if we look at the distribution of the y values we see that they are right skewed </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Trial]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[()]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggp11.png"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp11.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp11.png" width="800"/></imageobject><textobject><phrase>attachment:ggp11.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>to face the skewness we can transform the y-axis maybe with a square root function </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Trial]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_y_continuous]]></methodname><![CDATA[(]]><methodname><![CDATA[trans]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[sqrt"]]></phrase><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggp12.png"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp12.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp12.png" width="800"/></imageobject><textobject><phrase>attachment:ggp12.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>still a little skewed... </para></listitem><listitem><para>... so maybe we should try  </para></listitem></itemizedlist><screen><![CDATA[latex error! exitcode was 1 (signal 0), transscript follows:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex)
entering extended mode
(./latex_6f039602e893e250af4d36788a338962115664ab_p.tex
LaTeX2e <2018-12-01>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)
(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty)
No file latex_6f039602e893e250af4d36788a338962115664ab_p.aux.
! Missing $ inserted.
<inserted text> 
                $
l.10 x^
       {1/3}
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd)
! Missing $ inserted.
<inserted text> 
                $
l.11 \end{document}
                   
[1] (./latex_6f039602e893e250af4d36788a338962115664ab_p.aux) )
(see the transcript file for additional information)
Output written on latex_6f039602e893e250af4d36788a338962115664ab_p.dvi (1 page,
 296 bytes).
Transcript written on latex_6f039602e893e250af4d36788a338962115664ab_p.log.
]]></screen><itemizedlist><listitem><para>we first have to write a new transformation\small </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[xt1_3_trans]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[function]]></methodname><![CDATA[() ]]>
<![CDATA[+    ]]><methodname><![CDATA[trans_new]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[xt1_3"]]></phrase><![CDATA[, ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) ]]><methodname><![CDATA[x]]></methodname><![CDATA[**(1/3), ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) ]]><methodname><![CDATA[x]]></methodname><![CDATA[**3)]]>
<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Trial]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_y_continuous]]></methodname><![CDATA[(]]><methodname><![CDATA[trans]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[xt1_3"]]></phrase><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggp13.png"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp13.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp13.png" width="800"/></imageobject><textobject><phrase>attachment:ggp13.png</phrase></textobject></inlinemediaobject></ulink> </para><para>For standard transformation there is a short cut: </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Trial]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_y_sqrt]]></methodname><![CDATA[()]]>
</programlisting><itemizedlist><listitem><para>scale_x_log10() </para></listitem><listitem><para>scale_x_reverse() </para></listitem><listitem><para>scale_x_sqrt() </para></listitem></itemizedlist><para>Other transformation available: \small </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1">
</programlisting></section><section><title>Other Scales</title><itemizedlist><listitem><para>colour scales have also a continuous version (we have seen it in the first bar plot) </para><itemizedlist><listitem><para>scale_colour_gradient() </para></listitem><listitem><para>scale_colour_gradient2() </para></listitem><listitem><para>scale_colour_gradientn() </para></listitem></itemizedlist></listitem><listitem><para>scale_linetype_continuous() and scale_linetype_discrete() </para></listitem><listitem><para>scale_shape_continuous() and scale_shape_discrete() </para></listitem><listitem><para>scale_size_continuous() and scale_size_discrete() </para></listitem><listitem><para>scale_x_date() </para></listitem><listitem><para>scale_discrete() </para></listitem></itemizedlist></section><section><title>Exercises</title><para>* Create a scatter plot with Trial on the x-axis and TTime on the y-axis. Map colour to to age column. Looking at the pattern in the graph, is there relation between age and reaction time? * Make a plot which has a facet for each child containing the histogram of TTime, map fill to ..count.. (fill=..count.. inside  aes())  * then add scale_fill_gradient() and set its arguments low and high to, say green and red resp. (or make your own choice) * do the same but now do the facetting by testid (and second per Stim.Type level). What can you conclude from these graphs? </para><section><title>Solutions</title><itemizedlist><listitem><para>Create a scatter plot with Trial on the x-axis and TTime on the y-axis. Map colour to to age column. Looking at the pattern in the graph, is there relation between age and reaction time? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Trial]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[,]]><methodname><![CDATA[colour]]></methodname><![CDATA[=]]><methodname><![CDATA[Age_PRETEST]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_y_continuous]]></methodname><![CDATA[(]]><methodname><![CDATA[trans]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[xt1_3"]]></phrase><![CDATA[) ]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[ggp14.png"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp14.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp14.png" width="800"/></imageobject><textobject><phrase>attachment:ggp14.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>Make a plot which has a facet for each child containing the histogram of TTime, map fill to ..count.. (fill=..count.. inside  aes())  </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[..count..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_histogram]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[..density..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[Subject]]></methodname><![CDATA[) ]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp15.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp15.png" width="800"/></imageobject><textobject><phrase>attachment:ggp15.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>then add scale_fill_gradient() and set its arguments low and high to, say green and red resp. (or make your own choice) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[..count..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_histogram]]></methodname><![CDATA[() +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[Subject]]></methodname><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_fill_gradient]]></methodname><![CDATA[(]]><methodname><![CDATA[low]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[forestgreen"]]></phrase><![CDATA[,]]>
<![CDATA[+                         ]]><methodname><![CDATA[high]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[firebrick3"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp15.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp15.png" width="800"/></imageobject><textobject><phrase>attachment:ggp15.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>do the same but now do the facetting by testid (and second per Stim.Type level). What can you conclude from these graphs? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[..count..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_histogram]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[..density..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_fill_gradient]]></methodname><![CDATA[(]]><methodname><![CDATA[low]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[forestgreen"]]></phrase><![CDATA[,]]>
<![CDATA[+                         ]]><methodname><![CDATA[high]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[firebrick3"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp16.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp16.png" width="800"/></imageobject><textobject><phrase>attachment:ggp16.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>do the same but now do the facetting by testid (and second per Stim.Type level). What can you conclude from these graphs? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[..count..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_histogram]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[..density..]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[scale_fill_gradient]]></methodname><![CDATA[(]]><methodname><![CDATA[low]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[forestgreen"]]></phrase><![CDATA[,]]>
<![CDATA[+                         ]]><methodname><![CDATA[high]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[firebrick3"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp16.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/GridGraphics?action=AttachFile&amp;do=get&amp;target=ggp16.png" width="800"/></imageobject><textobject><phrase>attachment:ggp16.png</phrase></textobject></inlinemediaobject></ulink> </para></section></section><section><title>Hadleyverse</title><itemizedlist><listitem><para>stringr - easy string manipulation </para></listitem><listitem><para>lubridate - easy date time manipulation </para></listitem><listitem><para>reshape2, tidyr - data manipulation, melting </para></listitem><listitem><para>devtools, testthat - package developement </para></listitem><listitem><para>etc </para></listitem></itemizedlist></section></section></article>