R ggplot barplot fill based on two variables

2k views Asked by At

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

0

There are 0 answers