R is a free, open-source programming language designed for data analysis, statistics, and visualization.
R is especially popular in agriculture, biology, economics, and health research.
We use RStudio, which is a friendly interface for writing and running R code.
Field Plot Example
Example of a field experiment setup
R Markdown combines code, results, and explanations into one file.
It is used to create reports, assignments, or publications with both analysis and interpretation.
R Markdown files have the extension .Rmd and include: -
Text written in Markdown (like this!) - Code chunks inside triple
backticks
Example:
``` r
# This is an example of a code chunk
summary(cars) # This summarizes a built-in dataset
```
```
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
```
Packages are collections of functions that add specific abilities to R.
You can install them once using
install.packages("packagename"), and then load them each
time using library(packagename).
Here are the key packages we’ll use in this course:
readr and readxldplyr and tidyrggplot2agricolaeherelibrarianThe mean is the central value of a dataset. It’s used to summarize data.
Formula: \(\text{Mean} = \frac{\sum x}{n}\)
mean(c(5, 10, 15, 20))
## [1] 12.5
Most biological traits (like crop yield) follow a bell-shaped curve.
x <- seq(-4, 4, length=100)
y <- dnorm(x)
plot(x, y, type="l", lwd=2, main="Normal Distribution", ylab="Density")
Normal Distribution Curve
agricolae::LSD.test()In ag research, we use replicated plots in a field to test treatments.
Design
Source: ResearchGate – Example of RCBD layout
plotlylibrary(ggplot2)
library(plotly)
p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
geom_point(size = 3) +
labs(title = "MPG vs Weight", x = "Weight (1000 lbs)", y = "Miles per Gallon", color = "Cylinders") +
theme_minimal()
ggplotly(p)
You’ve just reviewed the basics of: - What R and R Markdown are - What packages we’ll use - What common statistical concepts mean - How field trials are designed - How to view interactive figures
👍 Ready to try hands-on examples in the next session!