-7

this graph is made by ggplots but I don't know how to eliminate the lines between the stacked bars (e.g. I want to combine two pink bars into one).

enter image description here

kelvinfrog
  • 435
  • 1
  • 8
  • 18
  • 3
    are we supposed to magically extract your code from that image? – rawr May 13 '16 at 19:43
  • 2
    `color = NA` to your `geom` will get rid of all black lines. If that's what you want, we're done. Otherwise we'll need your code and probably some data too. – Gregor Thomas May 13 '16 at 20:18
  • I second both comments. Please read (1) [how do I ask a good question](http://stackoverflow.com/help/how-to-ask), (2) [How to create a MCVE](http://stackoverflow.com/help/mcve) as well as (3) [how to provide a minimal reproducible example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). I.e., provide input data, the expected output, what lines of code you tried and in what they failed. – lukeA May 13 '16 at 22:08
  • Ok, let me post the code. – kelvinfrog May 13 '16 at 22:38

1 Answers1

2

Build the sum of the values for the two pink bars for each sample:

library(ggplot2)
library(reshape2)
# create sample data based on one of your last posts:
set.seed(1)
otumat = matrix(sample(1:100, 100, replace = TRUE), nrow = 10, ncol = 10)
rownames(otumat) <- paste0("OTU", 1:nrow(otumat))
colnames(otumat) <- paste0("Sample", 1:ncol(otumat))
df <- melt(otumat)
df <- rbind(df, df[which(df$Var1=="OTU10"), ])

# Build two plots - original one + aggregated one:
lst <- list(aes(x=Var2, y=value, fill=Var1), 
            geom_bar(stat="identity", color="black"), 
            labs(x=NULL, y=NULL))
p1 <- ggplot(df) + lst
p2 <- ggplot(aggregate(value~Var1+Var2, df, sum)) + lst
gridExtra::grid.arrange(p1, p2)

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100