I want to plot a stacked bar where the upper part is colored in the same way but with alpha. The images below give an idea, what I want is to have the magma
colors, but the upper part with alpha. I wonder if it helps more to have two plots and "stack" them together. The upper part (alpha) is the tam_loc
variable in the dataset. That is rural
areas.
If I put alpha
in aes
it produces the output, but I cannot manipulate the alpha degree
. Further, if I do this the legend now has a bar (mean value) for non alpha values. See image
The data is here.
My code looks like this:
ggplot(locPCP, aes(reorder(x=NOMGEO, -mean),y=mean, fill=bin, alpha=tam_loc)) +
geom_bar(stat="identity") +
scale_fill_manual(labels = c("> 8", "3.5 - 4", "3 - 3.5", "2.5 - 3", "2 - 2.5", "< 2"),
values = c(state_colors[2:7])) +
scale_x_discrete(name="State") +
scale_y_continuous(name="Emissions per capita (t CO2eq/year)", limits=c(0, 15)) +
geom_hline(yintercept=pcp2015, linetype="dashed",
color = "black", size=1) +
geom_hline(yintercept=pcp2030, linetype="dashed",
color = "red", size=1) +
geom_hline(yintercept=pcp2018, linetype="dashed",
color = "blue", size=1) +
theme_classic() +
theme(legend.position="top",
legend.text = element_text(size=15, color="black"),
legend.title = element_text(size=15, color="black"),
axis.text.x = element_text(size=15, color="black", angle = 90, vjust = 0.2, hjust=1),
axis.text.y = element_text(size=15, color="black"),
axis.title.x = element_text(size=15, color="black", vjust=-1),
axis.title.y = element_text(size=15, color="black")) +
geom_errorbar(aes(ymax=meanS, ymin=meanS), colour="white", width=0.5, size=1) # http://www.cookbook-r.com/Graphs/Lines_(ggplot2)/