Is it possible to make the transparency (alpha) appear as a continuous gradient in the ggplot legend? Currently, the plot looks like this:
Here, the different values for alpha are represented by dots in a different transparency. I would like it to be represented as a bar with a continuous transparency gradient as illustrated below (but as a gradient of transparency instead of color):
The code I use for making the plot is this:
df %>%
ggplot(aes(x = intraEU_trade_bymemberstate_pct,
y = gini_eurostat,
alpha = year,
size = GDP_percap_currentUSD,
color = as.factor(lowGDP_percap_currentUSD))) +
geom_point() +
geom_smooth(method="lm", formula = y ~ x, show.legend = FALSE, color = "#6c757d") +
theme_few() +
scale_colour_manual(name="GDP per capita \n(dummy)",
labels = c("Above-average", "Below-average"),
values = c("#046d9a", "#ce5348")) +
scale_alpha_continuous(range = c(0.1, 1)) +
scale_size(range=c(0.3, 4)) + # control the size of the dots
guides(alpha = guide_legend(order = 1),
size = guide_legend(order = 2),
color = guide_legend(order = 3)) +
labs(x = "Intra-EU trade (% of total trade)",
y = "Gini (%)",
alpha = "Year",
size = "GDP per capita \n(current USD)",
color = "GDP per capita")