I am currently attempting to use ggplot to create a bar chart with a single bar that is partially transparent.
I have the following code:
dt1 <- data.table(yr=c(2010,2010,2011,2011),
val=c(1500,3000,2000,1100),
x=c("a","b","a","b"))
ggplot() + geom_bar(data=dt1, aes(x=yr, y=val,fill=x),stat="identity") +
scale_x_continuous(breaks=dt1$yr)
This will create a simple chart with 2 columns with stacked data. I have tried the following code to adjust the 2011 value to have transparency, however I am not having much luck. Any pointers?
dt1[,alphayr:=ifelse(yr==2011,.5,1)]
ggplot() + geom_bar(data=dt1, aes(x=yr, y=val,fill=x),stat="identity", alpha=dt1$alphayr) +
scale_x_continuous(breaks=dt1$yr)