ggplot(data = gap_slope_long,
aes(x = year, y = gdpPercap, group = country, color = country)) +
geom_line(linewidth = 1.2, show.legend = FALSE) +
geom_point(size = 3, show.legend = FALSE) +
geom_text(
data = gap_slope_long |> filter(year == "1952"),
aes(label = country),
hjust = 1,
size = 3.5,
show.legend = FALSE
) +
geom_text(
data = gap_slope_long |> filter(year == "2007"),
aes(label = country),
hjust = -0.2,
size = 3.5,
show.legend = FALSE
) +
scale_y_continuous(labels = dollar_format()) +
coord_cartesian(clip = "off") +
labs(
x = NULL,
y = "GDP per capita",
title = "Slope graph: GDP per capita in 1952 vs 2007",
subtitle = "Selected European countries",
caption = "Data: gapminder"
) +
theme(plot.margin = margin(10, 60, 10, 60))