r - Phyloseq ggplot2 objects do not allow certain elements to be added -
I want to modify the plots produced by the phyloseq package (download it from Gitub). Phyloseq plots are ggplot2 objects, so I think I can add elements by adding ggplot2 objects to the phyloseq-built object. In some cases it works, but not in others, and I do not understand why for example:
is required (phyloseq) required (grid) Requires (ggplot2) (plyr) Phyloseq package requires GlobalPatterns Dataset #use from GP & lt; - GlobalPatterns #de wh0 of some preprocessing data; - genefilter_sample (gp, filterfun_sample (function (x)> 5), a = 0.5 * nsamples (GP)) GP1 & lt; - prune_taxa (wh0, gp) GP1 & lt; - transform_sample_counts (GP1, function (x) 1e + 06 * x / zodiac (x)) phylum.sum = tapply (taxa_sums (GP1), tax_table (GP1) [, "race"], yoga, na.rm = TRUE) Top5phyla = name (type (race yoga, tru)) [1: 5] GP1 & lt; - prune_taxa #ordination # (for the NMDS plot using taxonomical (GP1) [, "caste"]%% in% top5phyla), GP1) using a broad-curtiss distance GP.ord & # 39; plat_orbitation (GP1, GP) Now I add some envfit () arrows to the conspiracy from the package veg., Ford, type = "bipolot", color = "sample type", size = "ficha", title = "
See the previous questions:
is required (vegetarian)) # First, in L% C ("Feces", "Mock", "Skin", "Tongue") Human / not human variable man = get_variable (GP1, "Sample Type ") envfit sample_data (GP1) $ human $ for% human & lt; - factor (human) nmds.envfit & lt; - envfit (GP.ord $ points, env = as.data.frame (sample_data (GP1) $ Human), perm = 999 # #standard envfit str (nmds.envfit) #data for envfit arrow vec.sp.df & lt; -as.data.frame (cbind ((nmds.envfit $ factors $ centroids * sqrt ( Nmds.envfit $ factors $ r)), pvals = nmds.envfit $ $ pvals)) #this is required, see Gavin Simpson in the above link env.scores.nmds & lt; - as.data.frame ( Vec.sp.df [vec.sp.df $ pvals & lt; 0.05,]) # relevant envifit envifit env.scores.nmds with relevant scores & relevant scores from lt #extracts; - cbind (env.scores.nmds, env.variables = c ("human not", "human")) and then gives them their name env.scores. Nmds mult & lt; - 1 # It can change if the arrows need a different length ### We now add these vectors to p3 p3 + geom_segment (data = env.scor Es.nmds, aes (x = 0, xend = mult Double the length for the parity of # Algae plot () function for MDS1, y = 0, yend = mult * MDS2, arrow = arrow (length = unit (0.75, "cm"), color = "black" Envfit Check Nb. Think about the length of the arrow, if not familiar with the length, geom_text (data = env.scores.nmds, #labels, for example, "mult" for environment variable arrows. However, it returns an error in the arrow AES (x = mult * MDS1, y = mult * MDS2, label = env.variables), size = 6, hjust = -0.5)
: "Error in eval (expr, envir, enclos): 'id type' not found ''
If we try to add another type of GGPlot2 element, then it will work:
p3 + geom_hline (yintercept = 0.75)
error The message already tells you what to decide on your extra layer.
The Ggplot2 objects that you want to modify, in column variables, id.type
, either in p3 $ data or
$ data
One of the slots is your layers, and it is a beauty mapping argument that your new layer is passed completely if you do not overwrite it. Given that your extra layer specifies both X and Y in both cases, I suspect that id.type
is a faceting or color variable. In recent versions of Ggplot2, you have an argument Inherit.aes = FALSE
, which prevents inherited mapping, and in that case you will remember unspecified mapping. What is the result of this (for example, if both sides have a layer, I think, and if the color is given then the default color is given on the layer).
Alternatively, depending on the data in your new layers, the id.type
column depends on what you want to achieve.
Comments
Post a Comment