Stat_cor(aes(color = dataset), method = "spearman", label.y = 6)Ĭombining multiple plots. Stat_cor(aes(color = dataset), method = "spearman")įacet/split by data set, add regression line and confidence interval: ggscatter(expr, x = "GATA3", y = "ESR1", size = 0.3,į = "dataset", #scales = "free_x", The following plots show the association between GATA3 and ESR1 genes expression. Ovarian serous cystadenocarcinoma (OV) and.The data set contains the mRNA expression for five genes of interest - GATA3, PTEN, XBP1, ESR1 and MUC1 - from 3 different data sets: We’ll use the gene expression data set described in our previous tutorial: Facilitating Exploratory Data Visualization: Application to TCGA Genomic Data. P2<- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right") P1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top") Geom_density(data = iris, aes(x = Sepal.Width, fill = Species), Ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE)+ # Need to set coord_flip = TRUE, if you plan to use coord_flip() Geom_density(data = iris, aes(x = Sepal.Length, fill = Species), Pmain <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))+ Recently, in a tweet post, Claus Wilke provides the following solution for creating a perfect scatter plot with marginal density plots or histogram plots: library(cowplot) The problem with the above plots, is the presence of extra spaces between the main plot and the marginal density plots. Yplot <- ggboxplot(iris, x = "Species", y = "Sepal.Width", Xplot <- ggboxplot(iris, x = "Species", y = "Sepal.Length",Ĭolor = "Species", fill = "Species", palette = "jco", # Marginal boxplot of x (top panel) and y (right panel) Size = 3, alpha = 0.6, ggtheme = theme_bw()) Rel_widths = c(2, 1), rel_heights = c(1, 2))Īdd marginal boxplot: # Scatter plot colored by groups ("Species") Plot_grid(xplot, NULL, sp, yplot, ncol = 2, align = "hv", Xplot <- xplot + clean_theme() + rremove("legend") Yplot <- yplot + clean_theme() + rremove("legend") Yplot <- ggdensity(iris, "Sepal.Width", fill = "Species", Xplot <- ggdensity(iris, "Sepal.Length", fill = "Species", # Marginal density plot of x (top panel) and y (right panel) Sp <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width", # Scatter plot colored by groups ("Species") In the R code below, we provide a solution using the cowplot package. One limitation of ggExtra is that it can’t cope with multiple groups in the scatter plot and the marginal plots. P <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width", The function ggMarginal(), can be used to easily add a marginal histogram, density or boxplot to a scatter plot.įirst, install the ggExtra package as follow: install.packages(“ggExtra”) then type the following R code: # Add density distribution as marginal plot lect: character vector specifying some labels to show.To specify only the size and the style, use font.label = list(size = 14, face = “plain”). For example font.label = list(size = 14, face = “bold”, color =“red”). font.label: a list which can contain the combination of the following elements: the size (e.g.: 14), the style (e.g.: “plain”, “bold”, “italic”, “alic”) and the color (e.g.: “red”) of labels.label: the name of the column containing point labels.Legend( "bottomleft ", inset =c( - 0.0, 0), legend =levels( map.df $ Enterotype), bty = "n ", col = levels( map. Ordiellipse( ord, map.df $ SeqTech, label = TRUE, cex = 0.7, conf = 0.99, col = "brown ") Points( ord, disp = "si ", cex = 0.5, col = map.df $ Enterotype, pch = 19) Plot( x = orddata $ CCA1, y = orddata $ CCA2, type = "n ") ( ord.ef <- envfit( ord ~ fake, permu = 1000, data = map.df)) Sample_data( expt) $ fake <- 1 :nsamples( expt) O rddata <- ordplot $ data # add a fake variable to the experiment ( ordplot <- plot_ordination( expt, ord, "samples ", color = "Enterotype ", shape = "SeqTech ")) Ord = ordinate( expt ~ Enterotype, "CCA ", "bray ") E nterotype = subset_samples( enterotype, !is.na( Enterotype))Įnterotype = subset_samples( enterotype, SeqTech != "Sanger ")Įxpt = prune_taxa(names(sort(taxa_sums( enterotype), TRUE)), enterotype)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |