library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
library(cowsay)
## Warning: package 'cowsay' was built under R version 4.3.2
str(iris)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
# boxplot of sepal length by species
ggplot(iris, aes(x = Species, y = Sepal.Length)) +
geom_boxplot() +
xlab("Species") + ylab("Sepal Length (cm)") # provide custom axis labels
# scatterplot of sepal length vs. sepal width by species
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length,
group = Species, color = Species, fill = Species)) +
geom_point(stat = "identity") +
geom_smooth(method = "lm") + # use linear model (lm) to provide line of best fit
xlab("Sepal width (cm)") + ylab("Sepal length (cm)") +
theme_classic()
## `geom_smooth()` using formula = 'y ~ x'
plot(iris)
# Display an error
1 / 0
## [1] Inf
# Collapsing Create a long numeric vector
long_vector <- rnorm(25)
# Display the long vector
long_vector
## [1] -0.52476321 1.23150277 -1.51507589 1.33233861 0.71446752 0.13301393
## [7] -1.77427835 0.09784228 -1.45119911 0.70095587 -0.21866089 1.24983330
## [13] 0.69761392 -1.64761413 0.74320404 0.19610979 0.50293912 0.15656777
## [19] -1.17974671 -1.82854939 -0.15332823 0.06645317 -1.45188810 1.35441056
## [25] 1.40863010
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.