Gplots Library

Posted By admin On 11/04/22
  • #Load the gplots package library (gplots) # Get plots of group means and standard errors par (mfrow = c (1, 2)) plotmeans (logCvalue TrophicLevel, data = mammals, p = 0.95, connect = FALSE) plotmeans (logCvalue GroundDwelling, data = mammals, p = 0.95, connect = FALSE).
  • The R ggplot2 boxplot is useful for graphically visualizing the numeric data group by specific data. Let us see how to Create an R ggplot2 boxplot, Format the colors, changing labels, drawing horizontal boxplots, and plot multiple boxplots using R ggplot2 with an example.
  • A system for 'declaratively' creating graphics, based on 'The Grammar of Graphics'. You provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives to use, and it.
  • Browse other questions tagged r gplots or ask your own question. The Overflow Blog Podcast 307: Owning the code, from integration to delivery.

マイクロアレイ解析やオミックス解析でよく見かけるheatmap。 下記サイトを参考にheatmapの描き方を勉強したのでメモ。.

Jun 13th, 2014
Never
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!

Load Library Gplots

  1. library('gplots')
  2. hmcol = colorRampPalette(brewer.pal(9, 'GnBu'))(100)
  3. pdf='DESeq_Results.pdf'
  4. pdf(pdf,paper='a4')
  5. window=function(x){
  6. quartz()
  7. par(mfrow=c(1,1))
  8. }
  9. pdata=read.table('pdata.txt',header=TRUE)
  10. conds=as.vector(pdata$condition) # Backwards compatibility with anton's old scripts
  11. # Make the new fangled DESeq2 counts object direct from data.
  12. ddsHTSeq <- DESeqDataSetFromHTSeqCount(sampleTable = pdata, directory = '.', design= ~ condition)
  13. # They recommend reordering conditions, not sure why though or if this has any effect for us
  14. colData(ddsHTSeq)$condition <- factor(colData(ddsHTSeq)$condition,levels=levels(pdata$condition))
  15. # Normalisation
  16. # Dispersion
  17. # New Neg. Binomial test
  18. window()
  19. res <- results(dds)
  20. # Lets do Anton's regular plots based around raw or log2 transformed data.
  21. # Effect of Normalisation on counts
  22. par(mfrow=c(3,1))
  23. barplot(colSums(counts(dds, normalized=F)), col=as.factor(conds), las=2,cex.names=0.4,main='Pre Normalised Counts')
  24. legend('center',conds,fill=as.factor(conds),cex=0.6,horiz=TRUE)
  25. barplot(colSums(counts(dds, normalized=T)), col=as.factor(conds), las=2,cex.names=0.4,main='Post Normalised Counts')
  26. window()
  27. heatmap.2(cor(counts(dds,normalized=TRUE)),trace='none',main='Sample to Sample Correlation')
  28. # Sample PCA
  29. pca <- princomp(counts(dds,normalized=T))
  30. plot(pca$loadings, main='Principal Component Analysis', col=colors[pdata$condition], pch=19, cex=2)
  31. window()
  32. # They recommend these as alternatives to log2 visualisations.
  33. # Alternative to Log2 (n+1) transformations - Wolfie and Simon say they are better ?
  34. vsd <- varianceStabilizingTransformation(dds, blind=TRUE)
  35. #window()
  36. #meanSdPlot(assay(rld[notAllZero,]), ylim = c(0,2.5))
  37. #meanSdPlot(assay(vsd[notAllZero,]), ylim = c(0,2.5))
  38. select <- order(rowMeans(counts(dds,normalized=TRUE)),decreasing=TRUE)[1:200]
  39. hmcol <- colorRampPalette(brewer.pal(9, 'GnBu'))(100)
  40. heatmap.2(counts(dds,normalized=TRUE)[select,], col = hmcol,
  41. dendrogram='none', trace='none', margin=c(10,6))
  42. heatmap.2(assay(rld)[select,], col = hmcol,
  43. dendrogram='none', trace='none', margin=c(10, 6))
  44. heatmap.2(assay(vsd)[select,], col = hmcol,
  45. dendrogram='none', trace='none', margin=c(10, 6))
  46. mat <- as.matrix(distsRL)
  47. rownames(mat) <- colnames(mat) <- with(colData(dds),
  48. window()
  49. heatmap.2(mat, trace='none', col = rev(hmcol), margin=c(13, 13))
  50. print(plotPCA(rld, intgroup=c('condition')))
  51. sig_p=0.00001
  52. z=results(dds)
  53. hitlist = (abs(z$log2FoldChange) > sig_lfc) & (z$padj <= sig_p) & (!is.na(z$log2FoldChange)) & (!is.na(z$padj))
  54. window()
  55. plot(results(dds)$log2FoldChange,-log(results(dds)$padj,10),ylab='-log10(Adjusted P)',xlab='Log2 FoldChange',main='Volcano Plot',pch=19,cex=0.4)
  56. points(results(dds)[hitlist,'log2FoldChange'],-log(results(dds)[hitlist,'padj'],10),pch=19,cex=0.4,col='red')
  57. abline(v=-sig_lfc)
  58. heatmap.2(log2(counts(dds[hitlist,],normalized=TRUE)+1),col=hmcol,trace='none',cexRow=0.5,cexCol=0.5,main=paste('Differential RNAs P< ',sig_p))
  59. dev.off()
barplot2 {gplots}R Documentation

Enhanced Bar Plots

Install gplots library in r

Description

An enhancement of the standard barplot() function. Creates a bar plotwith vertical or horizontal bars. Can plot confidence intervals for eachbar, a lined grid behind the bars, change plot area color andlogarithmic axes may be used.

Usage

Arguments

height

either a vector or matrix of values describing thebars which make up the plot. If height is a vector, theplot consists of a sequence of rectangular bars with heightsgiven by the values in the vector. If height is a matrixand beside is FALSE then each bar of the plotcorresponds to a column of height, with the values in thecolumn giving the heights of stacked “sub-bars” making up thebar. If height is a matrix and beside isTRUE, then the values in each column are juxtaposedrather than stacked.

width

optional vector of bar widths. Re-cycled to length thenumber of bars drawn. Specifying a single value will no visibleeffect unless xlim is specified.

space

the amount of space (as a fraction of the average barwidth) left before each bar. May be given as a single number orone number per bar. If height is a matrix andbeside is TRUE, space may be specified bytwo numbers, where the first is the space between bars in thesame group, and the second the space between the groups. If notgiven explicitly, it defaults to c(0,1) if heightis a matrix and beside is TRUE, and to 0.2otherwise.

names.arg

a vector of names to be plotted below each bar orgroup of bars. If this argument is omitted, then the names aretaken from the names attribute of height if thisis a vector, or the column names if it is a matrix.

legend.text

a vector of text used to construct a legend forthe plot, or a logical indicating whether a legend should beincluded. This is only useful when height is a matrix.In that case given legend labels should correspond to the rows ofheight; if legend.text is true, the row names ofheight will be used as labels if they are non-null.

beside

a logical value. If FALSE, the columns ofheight are portrayed as stacked bars, and if TRUEthe columns are portrayed as juxtaposed bars.

horiz

a logical value. If FALSE, the bars are drawnvertically with the first bar to the left. If TRUE, thebars are drawn horizontally with the first at the bottom.

density

a vector giving the the density of shading lines, inlines per inch, for the bars or bar components.The default value of NULL means that no shading linesare drawn. Non-positive values of density also inhibit thedrawing of shading lines.

angle

the slope of shading lines, given as an angle indegrees (counter-clockwise), for the bars or bar components.

col

a vector of colors for the bars or bar components.By default, grey is used if height is a vector, andheat.colors(nrow(height)) if height is a matrix.

prcol

the color to be used for the plot region.

border

the color to be used for the border of the bars.

main, sub

overall and sub titles for the plot.

xlab

a label for the x axis.

ylab

a label for the y axis.

xlim

limits for the x axis.

ylim

limits for the y axis.

xpd

logical. Should bars be allowed to go outside region?

log

a character string which contains ‘'x'’ if the x axis isto be logarithmic, ‘'y'’ if the y axis is to be logarithmic and‘'xy'’ or ‘'yx'’ if both axes are to be logarithmic.

axes

logical. If TRUE, a vertical (or horizontal, ifhoriz is true) axis is drawn.

axisnames

logical. If TRUE, and if there arenames.arg (see above), theother axis is drawn (with lty = 0) and labeled.

cex.axis

expansion factor for numeric axis labels.

cex.names

expansion factor for names.

inside

logical. If TRUE, the lines which divideadjacent (non-stacked!) bars will be drawn. Only applies whenspace = 0 (which it partly is when beside = TRUE).

plot

logical. If FALSE, nothing is plotted.

axis.lty

the graphics parameter lty applied to the axisand tick marks of the categorical (default horzontal) axis. Notethat by default the axis is suppressed.

offset

a vector indicating how much the bars should be shiftedrelative to the x axis.

plot.ci

logical. If TRUE, confidence intervals are plottedover the bars. Note that if a stacked bar plot is generated, confidenceintervals will not be plotted even if plot.ci = TRUE

ci.l,ci.u

The confidence intervals (ci.l = lower bound, ci.u =upper bound) to be plotted if plot.ci = TRUE. Values must havethe same dim structure as height.

ci.color

the color for the confidence interval line segments

ci.lty

the line type for the confidence interval line segments

ci.lwd

the line width for the confidence interval linesegments

ci.width

length of lines used for the 't' at the end of confidenceinterval line segments, as a multple of width. Defaults to 0.5.

plot.grid

if TRUE a lined grid will be plotted behind the bars

grid.inc

the number of grid increments to be plotted

grid.lty

the line type for the grid

grid.lwd

the line width for the grid

grid.col

the line color for the grid

add

logical, if TRUE add barplot to current plot.

panel.first

An expression to be evaluated after the plot regioncoordinates have been set up, but prior to the drawing of the barsand other plot region contents. This can be useful to add additionalplot region content behind the bars. This will also work ifadd = TRUE

panel.last

An expression to be evaluated after the bars havebeen drawn, but prior to the addition of confidence intervals, alegend and the axis annotation

...

further graphical parameters (par) arepassed to plot.window(), title() andaxis.

Details

Gplots Library R

This is a generic function, it currently only has a default method.A formula interface may be added eventually.

Value

Gplots Library

A numeric vector (or matrix, when beside = TRUE), saymp, giving the coordinates of all the bar midpointsdrawn, useful for adding to the graph.

If beside is true, use colMeans(mp) for themidpoints of each group of bars, see example.

Install gplots library in r

Note

Prior to R 1.6.0, barplot behaved as if axis.lty = 1,unintentionally.0 (zero) and NA values in height will not be plotted ifusing logarithmic scales.If there are NA values in height and beside = FALSE,values after the NA will not be plotted in stacked bars.

Plots Library

Gplots Library

Author(s)

Original barplot() by R-Core. Enhancements by MarcSchwartz marc_schwartz@comcast.net

See Also

plot(..., type = 'h'), dotchart,hist.

Examples