{"id":3459,"date":"2023-02-17T09:03:05","date_gmt":"2023-02-17T09:03:05","guid":{"rendered":"https:\/\/hub.salford.ac.uk\/psytech\/?page_id=3459"},"modified":"2024-03-04T14:34:28","modified_gmt":"2024-03-04T14:34:28","slug":"getting-started-performance-visualisation-r","status":"publish","type":"page","link":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/","title":{"rendered":"Getting Started &#8211; Performance Visualisation in R"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"255\" height=\"198\" src=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png\" alt=\"\" class=\"wp-image-2988\" \/><\/figure>\n<\/div>\n\n\n<p>  <\/p>\n\n\n\n<p class=\"has-medium-font-size\">This course is aimed at beginners who have zero coding experience, to provide an introduction to how programming can be used to manipulate and visualise performance data. The programming language used throughout this course is R. R is a popular programming language with a wide range of tools. Specifically, R is great at visualising data. Given the timeframe of this course, I want to you be in the mindset of using R as a tool, rather than learning R itself.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">To write any R code, you&#8217;re going to need a code editor or <strong>Integrated Development Environment<\/strong>, or<strong> IDE<\/strong> for short. The IDE we are going to use is RStudio and we&#8217;re going to use it through Anaconda. Anaconda will help us with managing the packages we need to run our code. Don&#8217;t worry about understanding all this, remember we&#8217;re using R as a tool!<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"360\" src=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-1024x360.png\" alt=\"\" class=\"wp-image-3462\" srcset=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-1024x360.png 1024w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-300x105.png 300w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-768x270.png 768w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-1536x539.png 1536w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio-Logo-Flat-2048x719.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"223\" src=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-13.png\" alt=\"\" class=\"wp-image-2887\" style=\"width:282px;height:140px\" srcset=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-13.png 447w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-13-300x150.png 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<p> <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Install the Anaconda Envrioment<\/h2>\n\n\n\n<p class=\"has-medium-font-size\"> For this course, we are going to import an environment into Anaconda. You can download the environment from the <a href=\"https:\/\/testlivesalfordac.sharepoint.com\/:f:\/s\/PsyTech\/Ektl32BpbsRFlElCods0R1gBcWgOncCtnUmKzZKwzbq_iQ?e=8LtcBM\">course files (opens in a new tab)<\/a>.<br><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Install Anaconda Environment\" width=\"960\" height=\"720\" src=\"https:\/\/www.youtube.com\/embed\/PpLhokGFbcQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Launch RStudio<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">RStudio divides into four panes.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"552\" data-id=\"3466\" src=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio_Layout-1024x552.png\" alt=\"\" class=\"wp-image-3466\" srcset=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio_Layout-1024x552.png 1024w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio_Layout-300x162.png 300w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio_Layout-768x414.png 768w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/RStudio_Layout.png 1424w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Source<\/strong>\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Here is where you can write code and save it in a file to use later.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Console<\/strong>\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>The console executes the code you write in source. You can also execute code straight from the console. <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Environment \/ History<\/strong>\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>This pane will display the objects in your environment and display your command history.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Files \/ Plots \/ Packages \/ Help<\/strong>\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Here you will see your R project file directory, view plots, see packages, and access R help.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p> <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">It&#8217;s just a fancy calculator!<\/h2>\n\n\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-medium-font-size\">We&#8217;re going to break the ice by using RStudio as a calculator. In the <strong>console<\/strong> type your numbers and operator then hit enter. Give it a try! Open the &#8216;<strong>Click to reveal<\/strong>&#8216; to see what you should expect. <\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure class=\"wp-block-table aligncenter is-style-stripes has-medium-font-size\"><table><thead><tr><th class=\"has-text-align-center\" data-align=\"center\"><strong>Operator<\/strong><\/th><th class=\"has-text-align-center\" data-align=\"center\"><strong>Description<\/strong><\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">+<\/td><td class=\"has-text-align-center\" data-align=\"center\">Addition<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">&#8211;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Subtraction<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">*<\/td><td class=\"has-text-align-center\" data-align=\"center\">Multiplication<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\/<\/td><td class=\"has-text-align-center\" data-align=\"center\">Division<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-pb-accordion-item c-accordion__item js-accordion-item no-js\" data-initially-open=\"false\" data-click-to-close=\"true\" data-auto-close=\"false\" data-scroll=\"false\" data-scroll-offset=\"0\"><h3 id=\"at-34590\" class=\"c-accordion__title js-accordion-controller\" role=\"button\">Click to reveal \u2b07 \u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af<\/h3><div id=\"ac-34590\" class=\"c-accordion__content\">\n\n<p>Here is what to expect:<\/p>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"395\" src=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/console-1024x395.png\" alt=\"\" class=\"wp-image-3469\" srcset=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/console-1024x395.png 1024w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/console-300x116.png 300w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/console-768x296.png 768w, https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2023\/02\/console.png 1181w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n<\/div><\/div>\n\n\n\n<p> <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Putting the fun in function<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Hopefully, that wasn&#8217;t that bad! Now let&#8217;s introduce you to a classic programming rite of passage. You are going to use the <strong>print()<\/strong> <strong>function <\/strong>to print &#8220;Hello world!&#8221; into the console. Copy and paste the code below into the console and press enter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"Hello world!\")<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">You can replace the &#8220;Hello world!&#8221; with other words if you like.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"There are lots of possibilities with R\")<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">What happens if you try and print without quotation marks?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(There are lots of possibilities with R)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-pb-accordion-item c-accordion__item js-accordion-item no-js\" data-initially-open=\"false\" data-click-to-close=\"true\" data-auto-close=\"false\" data-scroll=\"false\" data-scroll-offset=\"0\"><h3 id=\"at-34591\" class=\"c-accordion__title js-accordion-controller\" role=\"button\">Click to reveal \u2b07 \u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af<\/h3><div id=\"ac-34591\" class=\"c-accordion__content\">\n\n<p class=\"has-vivid-red-color has-text-color has-medium-font-size\">Error: unexpected symbol in &#8220;print(There are&#8221;<\/p>\n\n\n<p class=\"has-medium-font-size\">Don&#8217;t be scared of errors, when programming you&#8217;re going to come across a lot of them. The reason this is happening is that, like natural languages, programming languages have <strong>syntax<\/strong>. Syntax is a set of rules that you must follow to ensure your code can be interpreted by the computer. If your syntax is not correct, when you try to run your code, you will receive an error. In this case, we are trying to print a <strong>character<\/strong>, R will only recognise a <strong>character <\/strong>if within quotation marks. <strong>Characters <\/strong>(also known as <strong>strings<\/strong>) are <strong>data types<\/strong>, we&#8217;ll talk about them more shortly.<\/p>\n\n\n<p> <\/p>\n\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Variables<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">We don&#8217;t have to type directly into the print function what we want to print. We can store that data in a <strong>variable<\/strong>. Let&#8217;s make a <strong>variable <\/strong>and use it with the print() function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var &lt;- \"print this please\"\nprint(my_var)<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">We use the assignment operator &lt;- to store &#8220;print this please&#8221; into the <strong>variable <\/strong>called my_var. Notice how we don&#8217;t have to use quotation marks when using the my_var in the print() function. You can change what is stored in my_var without having to change the second line of code. <\/p>\n\n\n\n<p class=\"has-medium-font-size\">What happens if you misspell your variable or type a capital letter when there isn&#8217;t one?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var &lt;- \"print this please\"\nprint(My_Var)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-pb-accordion-item c-accordion__item js-accordion-item no-js\" data-initially-open=\"false\" data-click-to-close=\"true\" data-auto-close=\"false\" data-scroll=\"false\" data-scroll-offset=\"0\"><h3 id=\"at-34592\" class=\"c-accordion__title js-accordion-controller\" role=\"button\">Click to reveal \u2b07 \u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af<\/h3><div id=\"ac-34592\" class=\"c-accordion__content\">\n<p class=\"has-vivid-red-color has-text-color has-medium-font-size\">Error in print(My_Var) : object &#8216;My_Var&#8217; not found<\/p>\n<p class=\"has-medium-font-size\">R is case-sensitive and not clever enough to know what you mean if you make a typo!<\/p>\n<p> <\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Data types<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Inputting a variable into the class() function will return the data type of that variable. Let&#8217;s try this out.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var &lt;- \"print this please\"\nclass(my_var)<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">R will tell you that my_var is a character. Let&#8217;s try numbers. Numbers do not need quotation marks. If you surround a number with quotation marks, R will treat it as a character.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var_number &lt;- 34\nprint(my_var_number)\nclass(my_var_number)<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Using variables to make more variables<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">The above code will print 34 and tell you that the data type of my_var_number is numeric. Variables are particularly useful when calculating new metrics, which is something we will be doing a lot of. You can see a basic introduction to this utility by running the following code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var_number &lt;- 34\nmy_var_number_2 &lt;- 97\nmy_var_total &lt;- my_var_number + my_var_number_2\nprint(my_var_total)\n# By the way, the hashtag allows you to write comments that aren't excuted!\n# You can change the numbers that the the first two variables contain, \n# without needing to change anything else in the code variables are \n# incredibly useful.<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Variables holding more than one value<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Up until now, we have been using variables that only hold a single value. Variables can hold many values, for example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var_numbers &lt;- c(1, 2, 3, 4, 5) # The c() here stands for combine, as in\n                                   # combine these values.\nclass(my_var_numbers)\nprint(my_var_numbers * 10)<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Using variables and functions to make more variables<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">We can also use other functions to manipulate our variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var_numbers &lt;- c(1, 2, 3, 4, 5) \n\nsum(my_var_numbers) # returns the sum of all the values in the variable\nlength(my_var_numbers) #returns the how many values are stored in the variable.\n\n# We can use the sum() and length() functions to calculate the mean.\nmy_var_mean &lt;- sum(my_var_numbers)\/length(my_var_numbers)\nprint(\"Below is the mean calculated from using the sum() and length() functions.\")\nprint(my_var_mean)\n\n# Alternatively, R does have a mean() function.\nprint(\"Below is the mean calculated from the mean() function.\")\nprint(mean(my_var_numbers))<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Conditional statements<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">At the start, we established we are using R as a tool. There is no expectation for you to remember everything we covered today. The importance is understanding the logic. We&#8217;re going to finish this Getting Started section by using <strong>conditional statements<\/strong> to quantify a variable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># The shots variable contains values on if a shot resulted in a miss or a goal.\nshots &lt;- c(\"Goal\", \"Miss\", \"Miss\", \"Miss\", \"Miss\", \"Goal\", \"Miss\")\n\n\n# <strong>ifelse()<\/strong> is a <strong>conditional statment<\/strong>. The code instructs, <strong>if<\/strong> the value in shots is \"Goal\" (indicated by the ==) then add a 1 to the goal_counter variable. <strong>Else<\/strong> add a 0 to the goal_counter variable.\ngoal_counter &lt;- ifelse(shots == \"Goal\", 1, 0)\n\n\n# The miss_counter uses the same logic as the goal_counter.\nmiss_counter &lt;- ifelse(shots == \"Miss\", 1, 0)\n\n# if you were to print the goal_counter, the output would be\n# print(goal_counter)\n# 1 0 0 0 0 1 0\n# This is because the ifelse() iterates through the shots list.\n# Therefore we need to sum the values so they present in the desired format.\ngoal_counter &lt;- sum(goal_counter)\nmiss_counter &lt;- sum(miss_counter)\n\nprint(\"This many goals:\")\nprint(goal_counter)\nprint(\"This many misses:\")\nprint(miss_counter)<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\">Challenge!<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Using the code from the last example. Calculate the percentage of shots that resulted in a goal.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Programming is a lot of problem-solving please do look things up, google is your friend!*<\/p>\n\n\n\n<p style=\"font-size:16px\"><em>*Other search engines available.  <\/em><\/p>\n\n\n\n<div class=\"wp-block-pb-accordion-item c-accordion__item js-accordion-item no-js\" data-initially-open=\"false\" data-click-to-close=\"true\" data-auto-close=\"false\" data-scroll=\"false\" data-scroll-offset=\"0\"><h3 id=\"at-34593\" class=\"c-accordion__title js-accordion-controller\" role=\"button\">Click to reveal \u2b07 \u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af\u23af<\/h3><div id=\"ac-34593\" class=\"c-accordion__content\">\n<p class=\"has-medium-font-size\">Don&#8217;t worry if your answer is slightly different, there are many ways to achieve the same thing!<\/p>\n<pre class=\"wp-block-code\"><code># The shots variable contains values on if a shot resulted in a miss or a goal.\nshots &lt;- c(\"Goal\", \"Miss\", \"Miss\", \"Miss\", \"Miss\", \"Goal\", \"Miss\")\ngoal_counter &lt;- ifelse(shots == \"Goal\", 1, 0)\nmiss_counter &lt;- ifelse(shots == \"Miss\", 1, 0)\ngoal_counter &lt;- sum(goal_counter)\nmiss_counter &lt;- sum(miss_counter)\n# Don't forget there are many ways to calculate this! \npercentage_goals &lt;- (goal_counter\/length(shots))*100\nprint(\"This many goals:\")\nprint(goal_counter)\nprint(\"This many misses:\")\nprint(miss_counter)\nprint(\"Percentage of goals:\")\nprint(percentage_goals)\n# To sense check we can also calculate the % misses\npercentage_misses &lt;- (miss_counter\/length(shots))*100\n# If our calculations are correct then we should get a total of 100 \nprint(percentage_goals + percentage_misses)<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>  <\/p>\n\n\n\n<p> <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\">\n<h2 class=\"wp-block-heading has-text-align-center\">&nbsp;<a href=\"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\">? Return to Overview<\/a> <\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\">\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/data-processing-performance-visualisation-in-r\/\">Next \u27a1<\/a><\/h2>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/r4ds.hadley.nz\/cover.png\" alt=\"\" style=\"width:-29px;height:-43px\" \/><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\">\n<h2 class=\"wp-block-heading\">Further resources:<\/h2>\n\n\n\n<p>If you wish to pursue R independently, I recommend the following online resources to aid you on your learning journey. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.w3schools.com\/r\/default.asp\">https:\/\/www.w3schools.com\/r\/default.asp <\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/r4ds.had.co.nz\/index.html\">https:\/\/r4ds.had.co.nz\/index.html<\/a><\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/yt3.googleusercontent.com\/dW6to0x5Crmeh7yi-YPLcQRqVrBtx2BSh8eoKTJbE8NbjloQ0sqlmdszIlxokJU_97-ndOt_=s900-c-k-c0x00ffffff-no-rj\" alt=\"\" style=\"width:238px;height:238px\" \/><\/figure>\n<\/div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This course is aimed at beginners who have zero coding experience, to provide an introduction to how programming can be used to manipulate and visualise performance data. The programming language used throughout this course is R. R is a popular programming language with a wide range of tools. Specifically, R is great at visualising data. [&hellip;]<\/p>\n","protected":false},"author":177,"featured_media":0,"parent":3430,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-3459","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302\" \/>\n<meta property=\"og:description\" content=\"This course is aimed at beginners who have zero coding experience, to provide an introduction to how programming can be used to manipulate and visualise performance data. The programming language used throughout this course is R. R is a popular programming language with a wide range of tools. Specifically, R is great at visualising data. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Salford PsyTech Home \u2192\u2302\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-04T14:34:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/\",\"url\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/\",\"name\":\"Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/wp-content\\\/uploads\\\/sites\\\/95\\\/2022\\\/06\\\/image-15.png\",\"datePublished\":\"2023-02-17T09:03:05+00:00\",\"dateModified\":\"2024-03-04T14:34:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/wp-content\\\/uploads\\\/sites\\\/95\\\/2022\\\/06\\\/image-15.png\",\"contentUrl\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/wp-content\\\/uploads\\\/sites\\\/95\\\/2022\\\/06\\\/image-15.png\",\"width\":255,\"height\":198},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/getting-started-performance-visualisation-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Salford PsyTech\",\"item\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Learn Programming\",\"item\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Performance Visualisation in R\",\"item\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/psytechsalford\\\/learn-programming\\\/performance-visualisation-r\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Getting Started &#8211; Performance Visualisation in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#website\",\"url\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/\",\"name\":\"Salford PsyTech Home\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#organization\",\"name\":\"Salford PsyTech Home\",\"url\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/wp-content\\\/uploads\\\/sites\\\/95\\\/2025\\\/02\\\/university-salford-logo-400x250-1.png\",\"contentUrl\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/wp-content\\\/uploads\\\/sites\\\/95\\\/2025\\\/02\\\/university-salford-logo-400x250-1.png\",\"width\":400,\"height\":250,\"caption\":\"Salford PsyTech Home\"},\"image\":{\"@id\":\"https:\\\/\\\/hub.salford.ac.uk\\\/psytech\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/","og_locale":"en_US","og_type":"article","og_title":"Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302","og_description":"This course is aimed at beginners who have zero coding experience, to provide an introduction to how programming can be used to manipulate and visualise performance data. The programming language used throughout this course is R. R is a popular programming language with a wide range of tools. Specifically, R is great at visualising data. [&hellip;]","og_url":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/","og_site_name":"Salford PsyTech Home \u2192\u2302","article_modified_time":"2024-03-04T14:34:28+00:00","og_image":[{"url":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/","url":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/","name":"Getting Started - Performance Visualisation in R - Salford PsyTech Home \u2192\u2302","isPartOf":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/#website"},"primaryImageOfPage":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/#primaryimage"},"image":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/#primaryimage"},"thumbnailUrl":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png","datePublished":"2023-02-17T09:03:05+00:00","dateModified":"2024-03-04T14:34:28+00:00","breadcrumb":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/#primaryimage","url":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png","contentUrl":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2022\/06\/image-15.png","width":255,"height":198},{"@type":"BreadcrumbList","@id":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/getting-started-performance-visualisation-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hub.salford.ac.uk\/psytech\/"},{"@type":"ListItem","position":2,"name":"Salford PsyTech","item":"https:\/\/hub.salford.ac.uk\/psytech\/"},{"@type":"ListItem","position":3,"name":"Learn Programming","item":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/"},{"@type":"ListItem","position":4,"name":"Performance Visualisation in R","item":"https:\/\/hub.salford.ac.uk\/psytech\/psytechsalford\/learn-programming\/performance-visualisation-r\/"},{"@type":"ListItem","position":5,"name":"Getting Started &#8211; Performance Visualisation in R"}]},{"@type":"WebSite","@id":"https:\/\/hub.salford.ac.uk\/psytech\/#website","url":"https:\/\/hub.salford.ac.uk\/psytech\/","name":"Salford PsyTech Home","description":"","publisher":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hub.salford.ac.uk\/psytech\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/hub.salford.ac.uk\/psytech\/#organization","name":"Salford PsyTech Home","url":"https:\/\/hub.salford.ac.uk\/psytech\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hub.salford.ac.uk\/psytech\/#\/schema\/logo\/image\/","url":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2025\/02\/university-salford-logo-400x250-1.png","contentUrl":"https:\/\/hub.salford.ac.uk\/psytech\/wp-content\/uploads\/sites\/95\/2025\/02\/university-salford-logo-400x250-1.png","width":400,"height":250,"caption":"Salford PsyTech Home"},"image":{"@id":"https:\/\/hub.salford.ac.uk\/psytech\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/pages\/3459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/users\/177"}],"replies":[{"embeddable":true,"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/comments?post=3459"}],"version-history":[{"count":28,"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/pages\/3459\/revisions"}],"predecessor-version":[{"id":3680,"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/pages\/3459\/revisions\/3680"}],"up":[{"embeddable":true,"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/pages\/3430"}],"wp:attachment":[{"href":"https:\/\/hub.salford.ac.uk\/psytech\/wp-json\/wp\/v2\/media?parent=3459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}