Considering the example data below:
df <- structure(list(Name = c("HFK", "AMW", "OPS", "QTM", "RKL",
"PDF", "CAD", "PMC", "NLY", "TWV"), Date = structure(c(18659, 19024,
19052, 19052, 19079, 19153, 19192, 19233, 19260, 19417),
class = "Date"), Value = c("121 M", "105 M", "90 M", "93 M",
"25 M", "56 M", "89 M", "121 M", "81 M", "50 M"), displ =
c(1, 0.45, 0.25, 0.75, 1, 0.50, 0.85, 0.25, 0.75, 1)),
row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
I want to draw a timeline with ggplot:
ggplot(df, aes(Date, displ, label = Name)) +
geom_point(size = 2) + theme_classic() + guides(color = FALSE) +
labs(title = "MY TITLE") +
theme(axis.line.y = element_blank(), axis.ticks = element_blank(),
axis.text.y = element_blank(), axis.title = element_blank(),
plot.title = element_text(size = 20, hjust = 0.5, face = "bold",
margin = margin(c(0.3,0,-1.7,0), unit = "in")),
axis.text.x = element_text(size = 13, color = "black",
margin = margin(c(0.05,0,0,0), unit = "in"), face = "bold"),
axis.line.x = element_line(size = 0.9)) +
scale_x_date(date_breaks = "1 year", date_minor_breaks = "1 month",
date_labels = "%Y") +
scale_y_continuous(expand = c(0, 0), limits = c(0,1.7)) + geom_label() +
geom_segment(aes(x = Date, xend = Date,
y = 0, yend = displ), size = 0.5)
I want to add the months to the plot as well, as a minor data label. but the only way I saw was using:
scale_x_date(date_breaks = "1 year", date_minor_breaks = "1 month",
date_labels = "%b-%Y") +
But that repeats the year for every months. I ant each month and year to be mentioned only once as a timeline. The desired output is:


