# install the `ggridges` package.
install.packages("ggridges")
library(ggridges)
library(tidyverse)
library(ggthemes)
library(hrbrthemes)
library(RColorBrewer)
library(ggrepel)
library(ggtext)
library(skimr)Homework 4
Add Labels and Make Notes on ggplot; Advanced ggplot Charts
📌 Directions
Submit one Quarto document (
.qmd) to Brightspace:danl-310-hw4-LASTNAME-FIRSTNAME.qmd
(e.g.,danl-310-hw4-choe-byeonghak.qmd)
Due: April 20, 2026, 11:59 P.M. (ET)
✅ Setup
Question 1
Use the following data.frame for Question 1.
formulais available ingeom_smooth()formula = y ~ log(x):geom_smooth()fits withy ~ log(x).

Question 2
Use the data.frame ncdc_temp and ggridges::geom_density_ridges() for Question 2.
ncdc_temp <- read_csv(
'https://bcdanl.github.io/data/ncdc_temp_cleaned.csv')
Question 3
Use the following data.frame for Question 3.
starbucks <- read_csv(
'https://bcdanl.github.io/data/starbucks.csv')Variable description
Product_Name: Product NameSize: Size of drink (short, tall, grande, venti)Milk: Milk Type type of milk used0none1nonfat22%3soy4coconut5whole
Whip: Whip added or not (binary 0/1)Serv_Size_mL: Serving size in mlCalories: KCalTotal_Fat_g: Total fat gramsSaturated_Fat_g: Saturated fat gramsTrans_Fat_g: Trans fat gramsCholesterol_mg: Cholesterol mgSodium_mg: Sodium milligramsTotal_Carbs_g: Total Carbs gramsFiber_g: Fiber gramsSugar_g: Sugar gramsCaffeine_mg: Caffeine in milligrams
Q3a
- Add the following two variables to
starbucksdata.framecaffeine_mgml: Caffeine in milligrams per mLcalories_kcml: Calories KCal per mL
Q3b
- Calculate a mean
caffeine_mgmland a meancalories_kcmlfor eachproduct_name.
Q3c
For the top 10
product_namein terms ofcaffeine_mgmland the top 10product_namein terms ofcalories_kcml, replicate the ggplot below.Use the following commands for showing texts in the plot:
# install.packages("showtext")
library(showtext)
showtext_auto()
font_add_google("Annie Use Your Telescope", "annie")- Use the following
annotate()geom to insert the starbucks image in the plot:
# install.packages("ggtext")
library(ggtext)
img_href <- "<img src='https://bcdanl.github.io/lec_figs/starbucks.png' width='100'/>"
annotate("richtext",
x = ,
y = ,
label = img_href,
fill = ,
size = ,
color = )- Use the following
geom_text_repel()geom to use theanniefont
geom_text_repel(size = ,
max.overlaps = ,
box.padding = ,
family = "annie")- Use the following colors for labels
caffeine_10 <- c(
"#1E3932",
"#006241",
"#00754A",
"#0A7F5A",
"#198C6A",
"#2E9B7A",
"#49AA8A",
"#6ABA9C",
"#8CC9AF",
"#AED8C2"
)
calories_10 <- c(
"#7F5539",
"#9C6644",
"#B5651D",
"#BC6C25",
"#C97A34",
"#D4915D",
"#DDA15E",
"#E6B980",
"#EBC799",
"#EFD2AD"
)- Use the color,
"#00704A", for the title.
Answer:
