This is my first time learning how to code and using R markdown so it has been quite the experience for the past week. Initially, it was a little intimidating delving into an area so alien to me but after a while it became a lot more comfortable as it seems quite intuitive and practice-based.
For this first week, my goal was to simply learn basic R coding and markdown and if I was particularly ambitious, how to graph some imported data. Through Danielle’s videos, I have learnt how to do this and that as well as add images:
From my trip to New Zealand some years ago
First, I created a new data set in an Excel spreadsheet, which was the career statistics of Rafael Nadal across different playing surfaces
After uploading it to Rstudio, I noticed that some commands were automatically generated in the ‘Console’ tab so I then ‘borrowed’ these to try to map the data set.
library(readxl)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
## ✓ tibble 3.0.6 ✓ dplyr 1.0.4
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
RAFA <- read_excel("RAFA.xlsx")
Following Danielle’s tutorials on using ggplot, I decided to start easy and make a plot with Surface on the x-axis and Win Percentage on the y-axis.
However, when plugging in the codes, I encountered an error with the y value Win%. I soon realised it was because the percentage sign must have been interpreted as some form of code when it is simply a placeholder in the data set so I corrected this with quotation marks and formed a simple plot.
skills <- ggplot(data = RAFA) +
geom_point(
mapping = aes(
x = Surface,
y = "Win%"
)
)
print (skills)
As you can see, it didn’t exactly turn out as I expected.
For whatever reason, the y-axis and its values got a bit muddled up, with the y-axis being the letter y and its lone value being Win%. I have no idea how on earth this happened.
In troubleshooting, I tried to make another graph with Wins (W) on the y-axis instead and it turned out perfect.
pleasework <- ggplot(data = RAFA) +
geom_point(
mapping = aes(
x = Surface,
y = W
)
)
print(pleasework)
So, I gather the error in the first graph must have arisen from the use of quotations but I do not know how else to input Win% without R interpreting the % sign as some command. In later attempts, I tried including the y in the quotations marks y = Win% but all that did was change the value from Win% to y = Win%.
After much time, I gave up and decided to leave it to a later date when I have watched more of Danielle’s lectures.
After many hours, I managed to get a grasp on the basics of markdown and touched on a little bit of R coding. A small win for me was succeeding in making a graph of some imported data I made in excel but as shown above, that didn’t go as planned. The second graph, however, worked brilliantly.
The main issue I faced was keying in the y-axis properly since the % sign in Win% did not cooperate well with R.
For next week, I will continue with the coding series to learn more about how to properly code and see if I can figure out how to fix the first graph, either through the videos or through my own experimentation. So far, I quite enjoy R markdown, although it does have its moments where it is a little more frustrating than it is fun.