0

I want to make a bar plot in ggplot for the following data set

df1 <- read.table(header = T, stringsAsFactors = F, text = "exp treat  status      volpah       md      npha      dif stand
    5     K levande 295.5445523 23.87077  682.8358 504.5073    5K
    5     K     död   0.4791241  5.90000  682.8358 504.5073    5K
    5     S levande 504.9863924 25.56250  959.4737 504.5073    5S
    5     S     död  56.0771468 23.51818  959.4737 504.5073    5S
    6     K levande 535.6004818 28.11731  814.1026 559.9508    6K
    6     S levande 575.2554808 26.55842 1031.6327 559.9508    6S
    6     S     död  15.3046561 23.88333 1031.6327 559.9508    6S
    7     K levande 514.7016052 31.63276  600.0000 674.2121    7K
    7     S levande 702.6114530 27.76596 1003.5354 674.2121    7S
   7     S     död  28.3993754 23.10000 1003.5354 674.2121    7S
   8     K levande 438.5132338 26.30132  836.4198 529.4397    8K
   8     K     död   5.9385875 12.68000  836.4198 529.4397    8K
  8     S levande 532.4194020 28.05556  879.8851 529.4397    8S
   8     S     död   2.9796976  8.95000  879.8851 529.4397    8S")

I want to have exp on the x axis, on the y axis volpah for each treat but in two colors depending on status

After lot of falls I made it this way

library(dplyr)
library(ggplot2)
df1 <- mutate(df1, stand = paste(exp, treat, sep =""))
ggplot(aes(x = stand, y = volpah, fill = factor(status) ), data = df1) + geom_bar(stat = "identity", position = "stack")

and I got that enter image description here

which is not satisfying me in 100%. I want to have sth like this but the bars should be divided acc to status

enter image description here

Mateusz1981
  • 1,817
  • 17
  • 33
  • You put `stand` instead of `exp` for x. Is it a typo? And you created `bars`, but you don't use it. –  Oct 23 '15 at 06:08
  • And also, what is going on with `bars`. You create it but you don't use it. What is the desired result, why are you unhappy? Labels? – drmariod Oct 23 '15 at 06:10
  • Why not 2 facets, one for each treatment? –  Oct 23 '15 at 06:21
  • I'd like to avoid adding `facet_wrap(~treat)` as it is harder to compare between `exp` and poorly pedagogical – Mateusz1981 Oct 23 '15 at 06:32
  • So I don't see how 4 informations can be represented and easily readable on a single plot. Maybe someone else can. –  Oct 23 '15 at 06:33
  • I agree with @Pascal, facets might be the way to go here. If you really want everything in one plot, you could consider condensing two informations(namely treatment and status) to one variable, and thus having four bars per exp. Or facet_grid by experiment, and have treatment on the x-axis. – Heroka Oct 23 '15 at 06:58
  • Does this answer your question? `ggplot(df1, aes(x = as.numeric(interaction(treat, exp)), y = volpah, fill = status)) + geom_bar(stat = "identity",color="white")` – Eric Fail Oct 26 '15 at 17:29

0 Answers0