class: center, middle, inverse, title-slide # Introduction to ggplot as an entry way to R for beginners ## Teaching Tomorrow’s Scientists:
An ASCB Virtual Meeting ### Mine Dogucu ### 2020-05-30
🔗
bit.ly/ascb-ggplot
--- layout: true <!-- This file by Mine Dogucu is licensed under a Attribution-ShareAlike 2.5 Generic License (CC BY-SA 2.5) More information about the license can be found at https://creativecommons.org/licenses/by-sa/2.5/ --> <div class="my-header"></div> <div class="my-footer"> CC BY-SA <a href="https://mdogucu.ics.uci.edu">Mine Dogucu</a></div> --- class: center, middle ## License <img src="img/cc-sa.png" width="100%" /> More information can be found [here](https://creativecommons.org/licenses/by-sa/2.5/) --- class: center middle <table align = "center"> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr> </tr> </table> --- class: center middle <table align = "center"> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> </table> --- class: center middle <table align = "center"> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> </table> --- class: center middle <table align = "center"> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> <tr style="font-size:28px"> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>]</td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> <td> .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#CAC5B3;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg>] </td> </tr> </table> --- ## A ggplot <img src="slides_files/figure-html/unnamed-chunk-3-1.png" style="display: block; margin: auto;" /> .footnote[Note: the boxes are intentionally purple] --- ## Background - `ggplot`'s gg stands for Grammar of Graphics. -- - Grammar of Graphics is a book by Leland Wilkenson. -- - The ggplot2 is an R package written by Hadley Wickham. --- class: center middle ## First Week Goals <table align = "center"> <tr style="font-size:28px"> <td> .large[Prerequisite <br>Knowledge <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M212.333 224.333H12c-6.627 0-12-5.373-12-12V12C0 5.373 5.373 0 12 0h48c6.627 0 12 5.373 12 12v78.112C117.773 39.279 184.26 7.47 258.175 8.007c136.906.994 246.448 111.623 246.157 248.532C504.041 393.258 393.12 504 256.333 504c-64.089 0-122.496-24.313-166.51-64.215-5.099-4.622-5.334-12.554-.467-17.42l33.967-33.967c4.474-4.474 11.662-4.717 16.401-.525C170.76 415.336 211.58 432 256.333 432c97.268 0 176-78.716 176-176 0-97.267-78.716-176-176-176-58.496 0-110.28 28.476-142.274 72.333h98.274c6.627 0 12 5.373 12 12v48c0 6.627-5.373 12-12 12z"/></svg>]</td> <td> .large[Access <br>R <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"/></svg>]</td> <td> .large[Visualize <br>Data <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> </tr> </table> --- ## Prerequisite Knowledge - Data Matrix - Cases / Observations (Rows) - Variables (Columns) - Numeric vs. Categorical Variables - Plot Types (histogram, bar plot, scatter plot etc.) --- ```r births ``` ``` ## fAge mAge weeks premature visits gained weight sexBaby smoke ## 1 31 30 39 full term 13 1 6.88 male smoker mother ## 2 34 36 39 full term 5 35 7.69 male non-smoker mother ## 3 36 35 40 full term 12 29 8.88 male non-smoker mother ## 4 41 40 40 full term 13 30 9.00 female non-smoker mother ## 5 42 37 40 full term NA 10 7.94 male non-smoker mother ## 6 37 28 40 full term 12 35 8.25 male smoker mother ## 7 35 35 28 premie 6 29 1.63 female non-smoker mother ## 8 28 21 35 premie 9 15 5.50 female smoker mother ## 9 22 20 32 premie 5 40 2.69 male smoker mother ## 10 36 25 40 full term 13 34 8.75 female non-smoker mother ## 11 27 19 32 premie 5 32 6.50 female non-smoker mother ## 12 35 34 40 full term 15 20 7.44 male non-smoker mother ## 13 25 19 41 full term 13 47 8.38 male smoker mother ## 14 36 33 38 full term 10 20 6.00 male non-smoker mother ## 15 27 27 39 full term 11 5 7.81 male smoker mother ## 16 24 23 38 full term 13 22 7.81 female non-smoker mother ## 17 33 40 36 premie 13 23 7.81 female non-smoker mother ## 18 NA 23 40 full term 10 30 7.31 male non-smoker mother ## 19 28 27 33 premie 6 18 4.75 male smoker mother ## 20 25 22 34 premie 10 20 3.75 male non-smoker mother ## 21 35 31 37 full term 12 37 8.06 female non-smoker mother ## 22 NA 38 32 premie 10 16 2.19 female smoker mother ## 23 NA 26 42 full term 15 30 7.38 male smoker mother ## 24 29 30 39 full term 10 43 6.88 female non-smoker mother ## 25 24 22 40 full term 16 34 6.88 female smoker mother ## 26 25 25 38 full term 19 13 7.63 female non-smoker mother ## 27 34 33 43 full term 13 25 9.13 male smoker mother ## 28 NA 20 39 full term 15 70 7.38 female smoker mother ## 29 NA 28 37 full term 13 35 8.25 female non-smoker mother ## 30 28 26 39 full term 15 45 7.19 female non-smoker mother ## 31 27 27 39 full term 14 31 7.56 female non-smoker mother ## 32 NA 21 36 premie 15 10 6.81 male non-smoker mother ## 33 NA 24 38 full term 16 50 3.75 female non-smoker mother ## 34 NA 25 38 full term 11 27 8.75 male non-smoker mother ## 35 33 30 37 full term 10 57 6.56 male non-smoker mother ## 36 27 25 40 full term 11 26 7.44 male non-smoker mother ## 37 NA 25 39 full term 5 37 6.00 female smoker mother ## 38 29 21 39 full term 18 13 7.75 female non-smoker mother ## 39 33 30 39 full term 9 42 7.81 male smoker mother ## 40 NA 24 39 full term 6 30 6.13 female smoker mother ## 41 NA 23 42 full term 9 22 8.81 male non-smoker mother ## 42 29 26 39 full term 14 65 7.75 female smoker mother ## 43 35 28 38 full term 10 25 6.88 male non-smoker mother ## 44 27 22 35 premie 12 30 4.69 male non-smoker mother ## 45 33 25 35 premie 15 18 6.75 male non-smoker mother ## 46 27 22 39 full term 12 30 6.94 female smoker mother ## 47 30 25 35 premie 15 40 4.50 male smoker mother ## 48 NA 23 44 full term 4 55 8.13 female smoker mother ## 49 21 22 40 full term 10 85 5.81 male non-smoker mother ## 50 NA 32 37 full term 8 30 6.81 female non-smoker mother ## 51 34 34 38 full term 11 23 7.25 male non-smoker mother ## 52 22 22 39 full term 14 29 7.19 female non-smoker mother ## 53 35 31 40 full term 10 45 8.00 female non-smoker mother ## 54 25 26 39 full term 12 40 8.38 male non-smoker mother ## 55 22 26 39 full term 12 31 7.31 male smoker mother ## 56 22 34 39 full term 12 57 9.69 male non-smoker mother ## 57 40 40 38 full term 13 38 7.31 male non-smoker mother ## 58 24 18 37 full term 8 25 6.19 male smoker mother ## 59 42 38 41 full term 15 35 10.13 female non-smoker mother ## 60 30 28 39 full term 13 0 7.50 female non-smoker mother ## 61 35 31 40 full term 15 32 6.25 male non-smoker mother ## 62 39 27 39 full term 12 58 8.56 male smoker mother ## 63 28 18 41 full term 10 11 6.50 female non-smoker mother ## 64 29 29 44 full term 12 51 8.50 male non-smoker mother ## 65 28 24 39 full term 11 NA 7.50 female non-smoker mother ## 66 33 35 38 full term 10 20 6.44 female smoker mother ## 67 29 31 36 premie 8 42 5.94 male smoker mother ## 68 19 20 34 premie 13 6 4.50 male non-smoker mother ## 69 NA 19 39 full term 11 48 8.38 female smoker mother ## 70 43 31 41 full term 5 20 7.06 female smoker mother ## 71 33 27 41 full term 15 38 7.00 male smoker mother ## 72 27 21 41 full term 8 26 5.94 female non-smoker mother ## 73 29 30 39 full term 15 44 6.38 male smoker mother ## 74 NA 20 37 full term 10 26 5.38 female smoker mother ## 75 NA 16 40 full term 4 12 6.00 female non-smoker mother ## 76 34 34 37 full term 17 35 6.88 female non-smoker mother ## 77 26 26 41 full term 10 68 9.31 male non-smoker mother ## 78 22 22 40 full term 13 0 6.50 male smoker mother ## 79 31 32 38 full term 6 27 6.75 female non-smoker mother ## 80 39 37 38 full term 5 45 5.13 male non-smoker mother ## 81 NA 37 38 full term 3 NA 7.50 male smoker mother ## 82 34 36 38 full term 4 25 6.88 male smoker mother ## 83 NA 32 33 premie 10 60 5.06 male non-smoker mother ## 84 30 24 41 full term 12 40 8.13 male smoker mother ## 85 30 29 39 full term 14 30 5.38 male non-smoker mother ## 86 27 24 40 full term 11 8 7.69 female non-smoker mother ## 87 NA 23 41 full term 14 19 7.88 female non-smoker mother ## 88 24 21 41 full term 13 40 7.88 female non-smoker mother ## 89 34 29 39 full term 15 24 8.25 female non-smoker mother ## 90 32 25 41 full term 13 50 7.75 female non-smoker mother ## 91 26 25 40 full term 10 25 7.00 male non-smoker mother ## 92 NA 41 33 premie 13 0 5.69 female non-smoker mother ## 93 26 23 42 full term 14 23 6.75 male non-smoker mother ## 94 25 34 41 full term 10 35 8.19 female non-smoker mother ## 95 24 19 40 full term 12 36 8.19 male non-smoker mother ## 96 35 31 39 full term 15 35 7.44 male non-smoker mother ## 97 35 36 38 full term 18 37 8.25 male non-smoker mother ## 98 28 25 40 full term 7 31 9.19 male non-smoker mother ## 99 34 31 40 full term 14 44 7.50 female non-smoker mother ## 100 35 33 40 full term 16 30 6.81 male non-smoker mother ## 101 30 25 40 full term 12 35 8.13 male non-smoker mother ## 102 26 20 41 full term 16 21 6.31 female smoker mother ## 103 24 22 39 full term 12 32 8.38 male non-smoker mother ## 104 NA 26 38 full term 14 40 8.00 male smoker mother ## 105 34 27 39 full term 16 24 8.88 male smoker mother ## 106 NA 20 40 full term 17 39 9.06 male smoker mother ## 107 26 17 38 full term 11 30 9.50 female non-smoker mother ## 108 NA 18 40 full term 12 13 8.75 male non-smoker mother ## 109 34 33 39 full term 10 40 8.06 male non-smoker mother ## 110 20 23 39 full term 15 56 7.31 male smoker mother ## 111 21 16 38 full term 15 75 7.56 female smoker mother ## 112 22 20 38 full term 8 45 7.44 female non-smoker mother ## 113 32 35 38 full term 17 55 7.50 female non-smoker mother ## 114 37 35 40 full term 16 32 7.31 female non-smoker mother ## 115 36 30 39 full term 11 21 7.88 male non-smoker mother ## 116 31 23 44 full term 14 40 6.81 male non-smoker mother ## 117 20 20 37 full term 12 22 5.94 female non-smoker mother ## 118 46 39 38 full term 10 35 6.75 male smoker mother ## 119 23 25 37 full term 8 53 7.69 female non-smoker mother ## 120 28 21 38 full term 12 40 7.38 male non-smoker mother ## 121 25 19 40 full term 16 37 7.94 male smoker mother ## 122 NA 24 39 full term 8 22 5.00 female smoker mother ## 123 17 20 39 full term 16 35 5.63 female non-smoker mother ## 124 27 23 43 full term 15 30 7.81 female non-smoker mother ## 125 33 27 41 full term 14 58 8.00 male non-smoker mother ## 126 NA 18 33 premie 7 40 1.69 male smoker mother ## 127 26 23 38 full term 5 28 7.19 female non-smoker mother ## 128 37 33 36 premie 11 15 6.31 male smoker mother ## 129 32 24 39 full term 8 23 6.88 female smoker mother ## 130 24 22 42 full term 7 21 6.50 female non-smoker mother ## 131 17 17 29 premie 4 10 2.63 female non-smoker mother ## 132 18 15 37 full term 12 76 8.44 male non-smoker mother ## 133 24 20 41 full term 16 35 7.19 male non-smoker mother ## 134 NA 21 41 full term 12 32 8.38 male non-smoker mother ## 135 20 17 40 full term 17 38 7.19 male non-smoker mother ## 136 25 22 39 full term 12 27 6.31 female smoker mother ## 137 33 33 38 full term 15 60 6.56 male non-smoker mother ## 138 23 21 40 full term 15 38 7.63 female non-smoker mother ## 139 36 28 39 full term 15 40 8.38 male non-smoker mother ## 140 31 29 41 full term 12 30 7.69 male smoker mother ## 141 NA 23 36 premie 2 27 5.88 female non-smoker mother ## 142 NA 19 39 full term 7 0 7.31 male smoker mother ## 143 47 24 40 full term 12 46 6.88 male non-smoker mother ## 144 NA 35 37 full term 10 25 5.63 male smoker mother ## 145 30 29 38 full term 17 55 7.00 female non-smoker mother ## 146 NA 17 40 full term 15 20 7.63 female non-smoker mother ## 147 NA 37 39 full term 5 20 8.19 female smoker mother ## 148 31 32 37 full term 12 22 6.00 female non-smoker mother ## 149 33 28 41 full term 10 30 8.13 male non-smoker mother ## 150 38 37 26 premie 5 25 3.63 male non-smoker mother ``` --- ```r glimpse(births) ``` ``` ## Rows: 150 ## Columns: 9 ## $ fAge <int> 31, 34, 36, 41, 42, 37, 35, 28, 22, 36, 27, 35, 25, 36, 2... ## $ mAge <int> 30, 36, 35, 40, 37, 28, 35, 21, 20, 25, 19, 34, 19, 33, 2... ## $ weeks <int> 39, 39, 40, 40, 40, 40, 28, 35, 32, 40, 32, 40, 41, 38, 3... ## $ premature <fct> full term, full term, full term, full term, full term, fu... ## $ visits <int> 13, 5, 12, 13, NA, 12, 6, 9, 5, 13, 5, 15, 13, 10, 11, 13... ## $ gained <int> 1, 35, 29, 30, 10, 35, 29, 15, 40, 34, 32, 20, 47, 20, 5,... ## $ weight <dbl> 6.88, 7.69, 8.88, 9.00, 7.94, 8.25, 1.63, 5.50, 2.69, 8.7... ## $ sexBaby <fct> male, male, male, female, male, male, female, female, mal... ## $ smoke <fct> smoker mother, non-smoker mother, non-smoker mother, non-... ``` --- If you wanted to make the following plot and R could understand English what would you tell R? Decide with your neighbor(s). <img src="slides_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" /> --- class: middle ## Three Steps of Making a basic ggplot - Decide on what dataset to plot. -- - Decide on what goes on the axes. -- - Decide on the type of the plot. --- ## Step 1 - Decide on what dataset to plot .left-panel[ ```r ggplot(births) ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-8-1.png)<!-- --> ] --- ## Step 2 - Decide on variables and their axes .left-panel[ ```r ggplot(births) + aes(x = smoke) ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-10-1.png)<!-- --> ] --- ## Step 3 - Decide on the type of plot .left-panel[ ```r ggplot(births) + aes(x = smoke) + geom_bar() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-12-1.png)<!-- --> ] --- ## Example <img src="slides_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> --- ## Example .left-panel[ ```r ggplot(births) + aes(x = weight) + geom_histogram() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-15-1.png)<!-- --> ] --- ## geom_bar() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> categorical </td> <td>     </td> </tr> </table> <br> <br> ```r ggplot(births) + aes(x = smoke) + geom_bar() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-17-1.png)<!-- --> ] --- ## geom_histogram() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> numeric </td> <td>    </td> </td> </tr> </table> <br> <br> ```r ggplot(births) + aes(x = weight) + geom_histogram() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-19-1.png)<!-- --> ] --- ## geom_boxplot() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> categorical </td> <td> numeric </td> </td> </tr> </table> <br> <br> ```r ggplot(births) + aes(x = smoke, y = weight) + geom_boxplot() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-21-1.png)<!-- --> ] --- ## geom_point() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> numeric </td> <td> numeric </td> </td> </tr> </table> <br> <br> ```r ggplot(births) + aes(x = weight, y = gained) + geom_point() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-23-1.png)<!-- --> ] --- class: middle center You can add layers on top of layers on top of layers on top of layers... --- ## geom_point() and geom_smooth() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> numeric </td> <td> numeric </td> </td> </tr> </table> <br> <br> ```r ggplot(births) + aes(x = weight, y = gained) + geom_point() + geom_smooth() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-25-1.png)<!-- --> ] --- ## geom_point() and geom_smooth() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> numeric </td> <td> numeric </td> </td> </tr> </table> We can set the smoothing method to be _lm_ (linear model). ```r ggplot(births) + aes(x = weight, y = gained) + geom_point() + geom_smooth(method = "lm") ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-27-1.png)<!-- --> ] --- ## geom_point() and geom_smooth() .left-panel[ <table> <tr> <th>x</th> <th>y</th> </tr> <tr> <td> numeric </td> <td> numeric </td> </td> </tr> </table> We can set _se_ (standard error) to FALSE ```r ggplot(births) + aes(x = weight, y = gained) + geom_point() + geom_smooth(method = "lm", se = FALSE) ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-29-1.png)<!-- --> ] --- class: center middle ## Colors .large[ 🌈 ] Pick your favorite color(s) from the list at: [bit.ly/colors-r](http:/bit.ly/colors-r) --- # color = ? .left-panel[ ```r ggplot(births) + aes(x = smoke) + geom_bar(color = 'cyan') ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-31-1.png)<!-- --> ] --- # fill = ? .left-panel[ ```r ggplot(births) + aes(x = smoke) + geom_bar(color = 'cyan', fill = 'coral') ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-33-1.png)<!-- --> ] --- # fill = ? .left-panel[ The fill argument can also be used for a variable. Note that this time fill is inside the `aes` function with the other variable. The colors are set by default. ```r ggplot(births) + aes(x = smoke, fill = premature) + geom_bar() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-35-1.png)<!-- --> ] --- #labs .left-panel[ ```r ggplot(births) + aes(x = weight, y = gained) + geom_point() + labs(x = "Birth Weight of the Baby", y = "Weight Gained by the Mother", title = "Relationship between Mother's and Baby's Weight", caption = "Based on a random sample of 100 births in North Carolina") ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-37-1.png)<!-- --> ] --- ## Plot Types <table align="center"> <th> Variable 1</th> <th> Variable 2</th> <th> Type of Plot</th> <th> Geom object</th> <tr> <td>Categorical</td> <td> </td> <td>Bar plot</td> <td>geom_bar() </td> </tr> <tr> <td>Numeric</td> <td> </td> <td>Histogram </td> <td>geom_histogram() </td> </tr> <tr> <td>Numeric</td> <td> </td> <td>Dot plot </td> <td>geom_dotplot()</td> </tr> <tr> <td>Numeric</td> <td> </td> <td>Box plot </td> <td> geom_boxplot()</td> </tr> <tr> <td>Categorical</td> <td>Categorical </td> <td>Stacked bar plot</td> <td>geom_bar() </td> </tr> <tr> <td>Categorical</td> <td>Numeric </td> <td>Side-by-side box plot</td> <td> geom_boxplot()</td> </tr> <tr> <td>Numeric</td> <td>Numeric </td> <td>Scatter plot</td> <td> geom_point()</td> </tr> </table> .footnote[Box plot for a single variable is slightly more difficult for beginners.] --- ## Why start with ggplot? - "A picture is worth a thousand words" -- - For beginners, making visuals is more interesting than calculating the median, interquartile range on a calculator. -- - There is always a learning curve for learning R, however starting with ggplot makes that curve less steep. -- - ggplot is widely used including by [BBC](https://bbc.github.io/rcookbook/), [fivethirtyeight](https://rdrr.io/cran/ggthemes/man/theme_fivethirtyeight.html), and [Associated Press](https://github.com/associatedpress/apstyle). --- ## A note on teaching ggplot .left-panel[ ```r ggplot(births, aes(x = smoke, y = weight)) + geom_boxplot() ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-39-1.png)<!-- --> ] --- ## A note on teaching ggplot .left-panel[ ```r ggplot(births) + geom_boxplot(aes(x = smoke, y = weight)) ``` ] .right-panel[ ![](slides_files/figure-html/unnamed-chunk-41-1.png)<!-- --> ] --- class: center middle ## First Week Goals <table align = "center"> <tr style="font-size:28px"> <td> .large[Prerequisite <br>Knowledge <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M212.333 224.333H12c-6.627 0-12-5.373-12-12V12C0 5.373 5.373 0 12 0h48c6.627 0 12 5.373 12 12v78.112C117.773 39.279 184.26 7.47 258.175 8.007c136.906.994 246.448 111.623 246.157 248.532C504.041 393.258 393.12 504 256.333 504c-64.089 0-122.496-24.313-166.51-64.215-5.099-4.622-5.334-12.554-.467-17.42l33.967-33.967c4.474-4.474 11.662-4.717 16.401-.525C170.76 415.336 211.58 432 256.333 432c97.268 0 176-78.716 176-176 0-97.267-78.716-176-176-176-58.496 0-110.28 28.476-142.274 72.333h98.274c6.627 0 12 5.373 12 12v48c0 6.627-5.373 12-12 12z"/></svg>]</td> <td> .large[Access <br>R <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"/></svg>]</td> <td> .large[Visualize <br>Data <br> <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M496 384H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-32c0-8.84-7.16-16-16-16zM464 96H345.94c-21.38 0-32.09 25.85-16.97 40.97l32.4 32.4L288 242.75l-73.37-73.37c-12.5-12.5-32.76-12.5-45.25 0l-68.69 68.69c-6.25 6.25-6.25 16.38 0 22.63l22.62 22.62c6.25 6.25 16.38 6.25 22.63 0L192 237.25l73.37 73.37c12.5 12.5 32.76 12.5 45.25 0l96-96 32.4 32.4c15.12 15.12 40.97 4.41 40.97-16.97V112c.01-8.84-7.15-16-15.99-16z"/></svg>] </td> </tr> </table> --- ## Accessing R (Three Ways) Local installation <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"/></svg> [Download R](https://mirror.las.iastate.edu/CRAN/) [Download RStudio](https://rstudio.com/products/rstudio/download/) Download ggplot2 and other required packages (e.g. `install.packages(ggplot2)`) <hr> Local Server <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M480 160H32c-17.673 0-32-14.327-32-32V64c0-17.673 14.327-32 32-32h448c17.673 0 32 14.327 32 32v64c0 17.673-14.327 32-32 32zm-48-88c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24zm-64 0c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24zm112 248H32c-17.673 0-32-14.327-32-32v-64c0-17.673 14.327-32 32-32h448c17.673 0 32 14.327 32 32v64c0 17.673-14.327 32-32 32zm-48-88c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24zm-64 0c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24zm112 248H32c-17.673 0-32-14.327-32-32v-64c0-17.673 14.327-32 32-32h448c17.673 0 32 14.327 32 32v64c0 17.673-14.327 32-32 32zm-48-88c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24zm-64 0c-13.255 0-24 10.745-24 24s10.745 24 24 24 24-10.745 24-24-10.745-24-24-24z"/></svg> Requires IT support IT can do the downloads for the students. <hr> RStudio Cloud <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 640 512"><path d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4z"/></svg> You download the packages. You have access to students work. Will not be free for teaching classes starting in Fall 2020 --- class: center middle Live Demo .large[<svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"/></svg> [bit.ly/ascb-project](https://bit.ly/ascb-project)] --- ## Teaching Tips - If you start with R Markdown as opposed to R files, that will be there "normal" for the learner. -- - Since there is a lot to learn all at once, avoid using a dataset that requires additional learning (e.g. cell biology) -- - Teach `aes()` where you think it makes the most sense. -- - Introduce colors (has a magical effect on the learner!) --- class: middle ## Resources (All Open-Access) - [OpenIntro Statistics Textbook](https://www.openintro.org/) for introducing students to data summaries and different types of plots (not necessarily using R) - [R for Data Science](https://r4ds.had.co.nz/data-visualisation.html#coordinate-systems) - [RStudio Cheat Sheets](https://rstudio.com/resources/cheatsheets/) --- class: center middle <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"/></svg> mdogucu@uci.edu <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"/></svg> MineDogucu <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg> mdogucu <svg style="height:0.8em;top:.04em;position:relative;fill:#7b7043;" viewBox="0 0 512 512"><path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"/></svg>[bit.ly/dogucu-talk](https://bit.ly/dogucu-talk)