1

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

Black
  • 31
  • 2
  • 2
    what have you tried so far? How about [showing some effort](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) or maybe a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – mnm Dec 21 '17 at 02:54

1 Answers1

-1

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()

Kent Johnson
  • 3,320
  • 1
  • 22
  • 23