Add annotation color bar to ggplot or ggvis barplot

889 Views Asked by At

Does anyone know how to add an annotation color bar to a ggplot or ggvis/plotly/... barplot?

An example would be like "Heatmap 1" below, with a color bar (blue and red) representing sample information as type a or type b:

An example of adding annotation color bar

1

There are 1 best solutions below

0
Kent Johnson On

If you use the type a/type b variable for the fill aesthetic you will get colored bars and a legend.


suppressPackageStartupMessages(library(tidyverse))

df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2))
ggplot(df, aes(trt, outcome, fill=trt)) +
  geom_col()