Blog 1: Data Representation
Introduction
I spent this past week slowly exploring R Studio to see its functionalities. Specifically, I looked through several resources such as TutorialsPoint in order to find examples of these actions in action (ha). I also used the incredible internal software "Help()" which allows you to put help() around any function/operation that is confusing and R provides a full description of what it does and how to use it with examples!
I found very quickly that I learned coding best through examples and customizing someone else's work. A broader picture of the mechanics (how instructions are embedded within each other and how to define variables) became clear through looking at patterns. I anticipate this will be my method of instruction with the students: short examples that they can build upon for their needs.
Through my noodling, it became clear the quickest thing a person can learn in R is how to plot and analyze data sets. Plot (Line and Scatter), BoxPlot, Histogram, Pie, and Bar charts are all very easily accomplished and their instructions (this is what I'm calling what's inside the brackets that you need to fill in) very similar to Excel, which I grew up with and am pretty good at. Here are some examples:
Scatter Plots
plot(x = (0:10),y = c(2, 2.2, 2.5, 2.8, 3.1, 4, 4.9, 6.2, 7.1, 8.3, 9.5), #the x and y coordinates split into strings [not real]xlab = "Time (years since 2000)", #the label for the x-axis
ylab = "Population (millions)", #the label for the y-axis
xlim = c(0,10), #max and min values for the x-axis
ylim = c(1,11), # max and min values for the y-axis
main = "Population of Mississauga from 2000 to 2010" #Title
x = (0:10)
y = c(2, 2.2, 2.5, 2.8, 3.1, 4, 4.9, 6.2, 7.1, 8.3, 9.5)
plot(x,y,
xlab = "Time (years since 2000)",
ylab = "Population (millions)",
xlim = c(0,10), ylim = c(1,11),
main = "Population of Mississauga from 2000 to 2010 (not real)")
> print(v)
[1] 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
[2] 2.0 2.2 2.5 2.8 3.1 4.0 4.9 6.2 7.1 8.3 9.5
Line Plots
Box Plots
boxplot(x,
xlab = "Grade 9 Class",
ylab = "Student Marks out of 50",
main = "Student grades for unit test 2",
horizontal = TRUE)
Histograms
- Add breaks between the bars using "breaks = c()" where the word inside the brackets can be "strurges", "fd", or "scott", presumably to describe the three types?
- Frequency type by using "freq = " where TRUE or FALSE can go in depending on wanting to use total values or probability density (of 1).
- "Right" for right- or left-closed bins
- Axis labels (as shown above)
- Axis max and min values (as shown above)
- Colour (col) and borders (border)
- And data labels on top of each bar (labels)
breaks="scott",
right="TRUE",
xlab="Bins",
ylab="Percent")
Comments
Post a Comment