ggplot transparency on individual bar

后端 未结 2 762
被撕碎了的回忆
被撕碎了的回忆 2021-02-10 08:07

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         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 09:01

    First you put the alpha inside the aes as suggested by @jazzurro. However, you should use factor for this to get a discrete scale. Then you can manually adjust the alpha scale.

    ggplot() + geom_bar(data=dt1, aes(x=yr, y=val, fill=x, alpha=factor(alphayr)), stat="identity") +
      scale_x_continuous(breaks=dt1$yr) +
      scale_alpha_manual(values = c("0.5"=0.5, "1"=1), guide='none')
    

提交回复
热议问题