Lecture 4
NC State University
ST 511 - Fall 2024
2024-08-28
– Are you keeping up with the prepare material?
– Are you posting on Slack?
– Take advantage of TA office hours!
– Quiz-1 released at 5:00pm (on Moodle)
– HW-1 released Thursday afternoon (on Moodle; due on Gradescope)
There is a Workflow and Formatting
section
– putting your name in the YAML at the top of the document
– Pipes %>%
, |>
and ggplot layers +
should be followed by a new line
– You should be consistent with stylistic choices, e.g. %>%
vs |>
We will add more rules once we explore the tidyverse stylings later in the semester!
Change in due date!
HW-1 is now due on Sunday Sep 8th at 11:59pm
Some topics on HW-1 we may not cover as in-depth until next week
– Finish summary statistics
– Understand the fundamentals of ggplot
– Build appropriate visualizations
– More practice with R
– What are the variables?
– What patterns / trend can you takeaway from this graph?
Golden Rule We let the type of variable(s) dictate the appropriate plot
– Quantitative
– Categorical
When we go through how to make graphs in R, we are going to be mindful on the type of variable(s) we are using.
mtcars
You want to create a visualization. The first thing we need to do is set up the canvas…
mtcars |>
ggplot()
mtcars |>
ggplot(
aes(
x = variable.name, y = variable.name)
)
aes: describe how variables in the data are mapped to your canvas
+
“and”
When working with ggplot functions, we will add to our canvus using +
mtcars |>
ggplot(
aes(
x = variable.name, y = variable.name)
)
+geom_point()
– Two quantitative variables
– One quantitative variable
– One categorical variable
– Two categorical variables
– One quantitative; One categorical
– summarise is used to calculate statistics
– na.rm is a common argument used to override NA
values during calculations
– ggplot() sets up our canvas
– aes maps variables from our data set to the canvas
– geom tells R what type of picture we want to paint