I already converted full dates (2/22/2022 is a Tuesday, so it shows as 3) to numbers (Sunday=1, Monday=2, ect..) Now I'm plotting using facet_wrap and it shows all the graphs labled as "1", "2", ect.... How can I get the labels of each one "Sunday", "Monday", "Tuesday," ect?
Asked
Active
Viewed 26 times
0
-
1See [How to make a great R reproducible example]( https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – TarJae Feb 22 '22 at 21:21
-
Why create numbers? Pull out the day label in a column: `your_data$day_of_week = lubridate::wday(your_data$date_column, label = TRUE)`. Then use that column. – Gregor Thomas Feb 22 '22 at 21:22
-
That would work perfectly. Thanks. – Joseph Fife Feb 22 '22 at 21:51
-
Please provide enough code so others can better understand or reproduce the problem. – Community Feb 22 '22 at 22:55
1 Answers
1
You can create a labeller
for the facet_wrap()
. It's quite straightforward. This is some dummy data to show how to set them up:
library(tidyverse)
df <- tibble(day = 1:4,
run1 = runif(4)*100,
run2 = runif(4)*100,
run3 = runif(4)*100) %>%
pivot_longer(-day)
# Labeller for facet titles - Set up a named vector
day_labeller <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
names(day_labeller) <- 1:7
# Plot
ggplot(df) +
geom_col(aes(x = name, y = value, fill = day)) +
facet_wrap(~day, labeller = labeller(day = day_labeller))

Tech Commodities
- 1,884
- 6
- 13