Create the figure in the solution for Problem 1, using the data included in the R Markdown file.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(dplyr)
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(corrgram)
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
##
## Attaching package: 'GGally'
##
## The following object is masked from 'package:corrgram':
##
## baseball
library(ggcorrplot)
library(ggalt)
## Registered S3 methods overwritten by 'ggalt':
## method from
## grid.draw.absoluteGrob ggplot2
## grobHeight.absoluteGrob ggplot2
## grobWidth.absoluteGrob ggplot2
## grobX.absoluteGrob ggplot2
## grobY.absoluteGrob ggplot2
ggplot(dat1,
aes(x = var1,
y = var2)) +
geom_point(aes(x = var1,
y = var2)) +
geom_smooth() +
labs(y = "Variable2",
x = "Variable1" )
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Create the figure in the solution for Problem 2, using the data included in the R Markdown file.
# 1. Check the relationships of my data
dat2 %>%
pairs()
# 2.
# custom function for density plot
my_density <- function(data, mapping, ...){
ggplot(data = data, mapping = mapping) +
geom_density(fill = "cornflowerblue", ...)
}
# custom function for scatterplot
my_scatter <- function(data, mapping, ...){
ggplot(data = data, mapping = mapping) +
geom_point(alpha = 0.5,
color = "orange")
}
ggpairs(dat2,
lower=list(continuous = my_scatter),
diag = list(continuous = my_density))
Create the figure in the solution for Problem 3, using the data included in the R Markdown file.
cor(dat3)
## var1 var2 var3
## var1 1.0000000 0.8785738 -0.9441741
## var2 0.8785738 1.0000000 -0.9650474
## var3 -0.9441741 -0.9650474 1.0000000
ggcorrplot(cor(dat3),
type = "lower") +
labs(title = "Correlations") +
theme(plot.background = element_rect(fill = NA,
color = "black"))
Create the figure in the solution for Problem 4, using the data included in the R Markdown file.
Create the figure in the solution for Problem 5, using the data included in the R Markdown file.
dat5.1 <- dat5 %>%
arrange(var1)
dat5.1$names = factor(names,
levels = names)
ggplot(dat5.1,
aes(x = names,
y = var1)) +
geom_segment(aes(xend = names),
yend = 0,
color = "darkgreen") +
geom_point(color = "darkgreen") +
ylim(c(0, 35)) +
labs(y = "Variable 1")
Create the figure in the solution for Problem 6, using the data included in the R Markdown file.
ggplot(books_checked_out,
aes(x = Time,
y = Total,
fill = Genre)) +
geom_area() +
labs(title = "Books Checked Out")
Create the figure in the solution for Problem 7, using the data included in the R Markdown file.
ggplot(books_checked_out2,
aes(y = Genre,
x = Time1,
xend = Time5)) +
geom_dumbbell(size = 0.5,
size_x = 3,
size_xend = 3,
colour = "black",
colour_x = "red",
colour_xend = "purple")
## Warning: Using the `size` aesthetic with geom_segment was deprecated in ggplot2 3.4.0.
## ℹ Please use the `linewidth` aesthetic instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Create the figure in the solution for Problem 8, using the data included in the R Markdown file.
library(RColorBrewer)
my_color<-brewer.pal(5,"Spectral")
pie(pie_dat,
col = my_color)