1

Here is an example data frame I am working with:

dat <- read.table(text = "Response Gene MAJOR SUB_CLONE
1 R DNMT3A 20 10
2 N DNMT3A 30 80
3 R BCOR 20 40
4 N BCOR 30 80", sep = "", header=T)

short.m <- melt(dat)

I would like to generate a plot where my y-axis is grouped based on variables "Gene/Response". And the colors indicate variable MAJOR or SUB_CLONE.

I am currently using the following code, however, the position and stat in geom_bar are stacking the variables MAJOR and SUB_CLONE over each other (as seen in the example). Instead I like that for example the first row would have the height of 30 (20 associated to light-green and 10 to dark-green).

ggplot(short.m, aes(x=Gene, y=value/100, group=Response, fill=Response, alpha=variable)) +
geom_bar(stat="identity",position="dodge", colour="black") +
scale_alpha_manual(values=c(0.1, 0.5, 1)) +
coord_flip()

I greately appreciate your help.

Thank You, NF

enter image description here

  • 1
    It sounds like you want to combine stacking and dodging. If so, there are many possible duplicates on SO. See, for example, [here](http://stackoverflow.com/questions/12715635/ggplot2-bar-plot-with-both-stack-and-dodge) and [here](http://stackoverflow.com/questions/21409850/generate-paired-stacked-bar-charts-in-ggplot-using-position-dodge-only-on-some). Also [this](http://stackoverflow.com/questions/18165863/multirow-axis-labels-with-nested-grouping-variables/36337286#36337286) to make facets look more like dodging. – aosmith Dec 20 '16 at 21:24
  • 1
    Like `ggplot(short.m, aes(x=interaction(Gene,Response), y=value/100, fill=Response, alpha=variable)) + geom_bar(stat="identity",colour="black") `? I'm not sure I understand what the result should look like. Also, I'm doing a color blindness check, now. – lukeA Dec 20 '16 at 21:24

0 Answers0