0

I have used the following code to generate this plot:

Cb64k <- c("#7A87A1", "#788D66",
           "#885578", "#FAD09F", "#FF8A9A", "#D157A0", "#BEC459", "#456648", "#0086ED", "#886F4C",
           "#34362D", "#B4A8BD", "#00A6AA", "#452C2C", "#636375", "#A3C8C9", "#FF913F", "#938A81",
           "#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#3B9700", "#04F757", "#C8A1A1", "#1E6E00",
           "#7900D7", "#A77500", "#6367A9", "#A05837", "#6B002C", "#772600", "#D790FF", "#9B9700",
           "#549E79", "#FFF69F", "#201625", "#72418F", "#BC23FF", "#99ADC0", "#3A2465", "#922329",
           "#5B4534", "#FDE8DC", "#404E55", "#0089A3", "#CB7E98", "#A4E804", "#324E72", "#6A3A4C")

Species2 = group$Species
Species2 = Species2[Species2 != "Filler"]

ggplot(group, aes(x = variable, y = value, fill = Species)) +
  geom_bar(position = "fill", stat = "identity") +
  scale_fill_manual(breaks = Species2, values = Cb64k) +
  scale_y_continuous(labels = percent_format()) +
  theme(legend.position = "bottom", text=element_text(size=11),
        axis.text.x = element_text(angle=0, vjust=1)) +
  guides(fill = guide_legend(ncol=5)) +
  facet_grid(rows=vars(Program), scales = "free_x", space = "free_x") +
  ggtitle(opt$gtitle) +
  xlab("Patient ID") + ylab("Relative Abundance")

Example image

As you can see Debaryomyces fabryi is included in the plot (empty segments in lower graph), however it looks like a transparent colour was assigned to it so it isn't really visible. How can I fix this?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
mrad
  • 173
  • 1
  • 11
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 21 '20 at 03:51

1 Answers1

0

You should try to filter in ggplot2 by subsetting your dataframe::

ggplot(subset(group, Species != "Debaryomyces fabryi"), aes(x = variable, y = value, fill = Species)) +
  geom_bar(position = "fill", stat = "identity") +
  scale_fill_manual(breaks = Species2, values = Cb64k) +
  scale_y_continuous(labels = percent_format()) +
  theme(legend.position = "bottom", text=element_text(size=11),
        axis.text.x = element_text(angle=0, vjust=1)) +
  guides(fill = guide_legend(ncol=5)) +
  facet_grid(rows=vars(Program), scales = "free_x", space = "free_x") +
  ggtitle(opt$gtitle) +
  xlab("Patient ID") + ylab("Relative Abundance")

Does it answer your question ?

If not, please provide a reproducible example of your dataset by following this link: How to make a great R reproducible example

dc37
  • 15,840
  • 4
  • 15
  • 32