1 / 200 * 30
[1] 0.15
#> [1] 0.15
59 + 73 + 2) / 3 (
[1] 44.66667
#> [1] 44.66667
sin(pi / 2)
[1] 1
#> [1] 1
Getting Started
Jihong Zhang*, Ph.D
Educational Statistics and Research Methods (ESRM) Program*
University of Arkansas
January 15, 2025
1 / 200 * 30
.<-
, for example, x <- 3 * 4
.c()
, like primes <- c(2, 3, 5, 7, 11, 13)
.[1] 0.15
[1] 44.66667
[1] 1
_
, and .
.function_name(value1, value2)
.ggplot()
and geom_point()
are functions included in the package ggplot2
ggplot2
using library()
functionmapping
, color
, and size
are called arguments of geom_point()
for detailed settings.Let’s try the following steps:
Opening a new script as we just did
Give the script a name by saving the current new unnamed script (ctrl + S
for Win and Cmd + S
for Mac)
A good convention is to use a descriptive name, with lower case letters, no spaces, only hyphens to separate words, and then followed by the suffix .R
. We will call this script my-first-script.R
.
Now we are ready to start editing our first script.
We install a R package called tidyverse
in Console.
We add the code to load the tidyverse
package in the script
We add the following code in the script. Run the whole script.
install.packages("remotes") # install one package called "remotes"
library("remotes") # load the package into your R session
install_github(repo = "JihongZ/ESRM6990V") # install one GitHub package from my GitHub repository
library(ESRM6990V) # load the package into your R session
jihong(details = TRUE) # call one function called "jihong" from the package
# Left
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_smooth()
# Middle
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_smooth(aes(group = drv))
# Right
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_smooth(aes(color = drv), show.legend = FALSE)
mpg
displ
: A car’s engine size, in liters. A numerical variable.
hwy
: A car’s fuel efficiency on the highway, in miles per gallon (mpg). A car with a low fuel efficiency consumes more fuel than a car with a high fuel efficiency when they travel the same distance. A numerical variable.
class
: Type of car. A categorical variable.
Comments
#
, which allows for inline documentation.