I am trying to expand my scale to allow for left justifying the text annotation via ggrepel.
However, I am having trouble keeping the same serve_YYYY_Q ticks. Ideally I want the padding that is provided by using expand = expansion(add = .6) but really only want the increase to occur to the right of the graph and not the left. Where am I going wrong?
library(tidyverse)
library(ggplot2)
data <- tibble(serv_YYYY_Q=as.yearqtr(c("2019 Q3","2019 Q3","2019 Q4","2019 Q4","2020 Q1","2020 Q1","2020 Q2","2020 Q2")),
labels = c("Florida","All States","Florida","All States","Florida","All States","Florida","All States"),
share = c(0, 0, 0.001, 0, 0.001, 0.002, 0.029, 0.03))
# Plot and Format
fig <- ggplot(data,aes(x = serv_YYYY_Q, y = share, color = labels)) +
geom_line() +
scale_color_manual(
values = c("#1192FF","#FFB15C")) +
geom_text_repel(data=tail(data,2),aes(y = share, label = labels),
size = 2.5, hjust=0,nudge_x=.05,
nudge_y = 0.001,
direction = "y", segment.color = "white")+
labs(title = "Telemedicine as a Percent of Physician Payments", subtitle ="") +
scale_x_yearqtr(format = "%Y-Q%q",expand = expansion(add = .6)) +
scale_y_continuous(labels = function(y) paste0(round(y*100,0),"%"), limits = c(0, 0.15),
breaks = seq(0, 0.15, by = .05), expand = c(.005,0)) +
coord_cartesian(clip = 'off') +
my_theme +
theme(plot.title = element_text(size = 8, hjust= -.2, vjust= 0, color = "#595959", face = "bold"),
plot.subtitle = element_text(size = 7, hjust= 0, vjust=1, color = "#595959"),plot.margin=unit(c(6, 6, 6, 6), "points"), legend.position = "none")