rbar-chartgradientwaterfall

How can I add a gradient to my waterfall plot?


Just started working with R and followed a tutorial to create a waterfall plot. It worked with very well when using dichotomous values:

col <- ifelse(tumor_tidy_wp$zr == "YES", "#1B9E77", "#D95F02")

barplot(tumor_tidy_wp$maxchange, col=col, border="Black", space=0.5, ylim=c(-75,75),
      main = "Waterfall plot", ylab="Change from baseline (%)",
      cex.axis=1.2, cex.lab=1.4, legend.text=c("Yes","No"),
      args.legend=list(title="Uptake 89Zr on any time-point", fill=c("#1B9E77","#D95F02"), border=NA, cex=0.9)) +
      theme(axis.line.x = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank(),
      axis.title.y = element_text(face="bold",angle=90))

Waterfallplot_dichotomous

I also have a continous scale of this value and in stead of YES/NO I would like to have a gradient instead, but I cannot get this to work. I tried to use versions of scale_fill() but failed. Is there another way?


Solution

  • Fixed it myself by changing from using barplot to the ggplot + geom_bar + scale_fill_gradient2 like so

    ggplot(data=tumor_tidy_wp, aes(x=x, y=maxchange, fill=IA)) + geom_bar(stat="identity") + scale_fill_gradient() + theme_classic2() + expand_limits(y=c(-60, 60)) + ylab("Change from baseline(%)")

    Waterfall plot with gradient