In the following example, I would like to do the following:
- Change xlab and ylab ( I tried but x and y labs are not changing).
- Present years as integers i.e. get rid of decimals in x-axis.
- Show all the years.
suppressWarnings(suppressMessages(library(tidyverse)))
#######
# Data
#######
set.seed(123)
toy_data <- tibble(
year = 2008:2017,
mean = rnorm(10, mean = 50, sd = 20),
median = rnorm(10, mean = 40, sd = 15)
) %>%
pivot_longer(
cols = mean:median,
names_to = "stats",
values_to = "delay"
)
#######
# Plot
######
toy_data %>%
ggplot(aes(x = year, y = delay , color = stats)) +
geom_line() +
geom_point() +
stat_summary(geom = "text", fun = quantile,
aes(label=sprintf("%1.0f", ..y..)),
position = position_nudge (x= -0.25), size=2.5) +
labs(
subtitle = "Yearly Stat",
color = "Statistics",
ylab = "Delay",
xlab = "Year"
)

Created on 2020-11-15 by the reprex package (v0.3.0)