cut plots in the plot window

Description of issue -

I am new using R. I am using phyloseq to analyze microbiome data. I am using plot_bar(physeq, fill = "XXXX") to get the taxonomic plots. The code is working fine but when I try to plot the taxa by class, order, family, genus, or species, the plots are so big that is only shown a part of the legend. I tried to export and zoom by still cannot see the full graph. I also tried to reset the plot setting using:

dev.off()
plot(cars)

but it did not work.

Please could you help me!

library(phyloseq)
library("ggplot2"); packageVersion("ggplot2")
theme_set(theme_bw())


#Import Data 

lakewaterdataTG <- import_biom("D:\\SeqData LakeWaterExp\\QIIME v.5 Default Quality by sample Nephele Job 1da5fbcee51a\\outputs\\core_diversity\\taxa_plots_TreatmentGroup\\TreatmentGroup_otu_table.biom")
mapfileTG <- import_qiime_sample_data("D:\\SeqData LakeWaterExp\\QIIME v.5 Default Quality by sample Nephele Job 1da5fbcee51a\\outputs\\core_diversity\\taxa_plots_TreatmentGroup\\TreatmentGroup_map.txt")
lakewaterdataTG <- merge_phyloseq(lakewaterdataTG, mapfileTG)
lakewaterdataTG

#Rename the taxonomic levels
ncol(tax_table(lakewaterdataTG))
colnames(tax_table(lakewaterdataTG)) <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")

#OTU Table and taxa Tables

OTU = otu_table(lakewaterdataTG, taxa_are_rows = TRUE)
TAX = tax_table(lakewaterdataTG)
OTU

# combine them into a phyloseq object

physeq = phyloseq(OTU, TAX)
physeq

dev.off()
plot(cars)

plot_bar(physeq, fill = "Kingdom")

plot_bar(physeq, fill = "Phylum")

plot_bar(physeq, fill = "Class")

plot_bar(physeq, fill = "Order")

plot_bar(physeq, fill = "Family")

plot_bar(physeq, fill = "Genus")

plot_bar(physeq, fill = "Species")

System Information:

  • RStudio Edition: (Desktop or Server) Desktop
  • RStudio Version: Version 1.1.456 – © 2009-2018 RStudio, Inc.
  • OS Version: windows 10 education version 1803 OS build 17134.254
  • R Version: R version 3.5.1 (2018-07-02)
  • sessionInfo():

Referred here from support.rstudio.com

This is happening because you likely have a huge amount of legend options (most probably with long names) and this is overshadowing the plot itself. You should try filtering the number of samples that you look at when you go to lower taxonomic levels or only look at a subset of taxa. For example, instead of looking at all genera in your dataset, try to look only at the genera that are present in your most abundant phyla.

Even if you could fix the legend issue, your abundance plots would likely be impossible to interpret because of the large number of individual taxonomic assignments and the limitations on discrete color distinction.

You should take a look at filter_taxa, subset_taxa, and subset_samples (and other similar functions in the phyloseq package) functions


In addition, it looks like your code was not formatted correctly to make it easy to read for people trying to help you. Formatting code allows for people to more easily identify where issues may be occurring, and makes it easier to read, in general. I have edited you post to format the code properly.

In the future please put code that is inline (such as a function name, like mutate or filter) inside of backticks (`mutate`) and chunks of code (including error messages and code copied from the console) can be put between sets of three backticks:

```
example <- foo %>%
  filter(a == 1)
```

This process can be done automatically by highlighting your code, either inline or in a chunk, and clicking the </> button on the toolbar of the reply window!

This will help keep our community tidy and help you get the help you are looking for!

For more information, please take a look at the community's FAQ on formating code