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の描き方を勉強したのでメモ。.
Load Library Gplots
- library('gplots')
- hmcol = colorRampPalette(brewer.pal(9, 'GnBu'))(100)
- pdf='DESeq_Results.pdf'
- pdf(pdf,paper='a4')
- window=function(x){
- quartz()
- par(mfrow=c(1,1))
- }
- pdata=read.table('pdata.txt',header=TRUE)
- conds=as.vector(pdata$condition) # Backwards compatibility with anton's old scripts
- # Make the new fangled DESeq2 counts object direct from data.
- ddsHTSeq <- DESeqDataSetFromHTSeqCount(sampleTable = pdata, directory = '.', design= ~ condition)
- # They recommend reordering conditions, not sure why though or if this has any effect for us
- colData(ddsHTSeq)$condition <- factor(colData(ddsHTSeq)$condition,levels=levels(pdata$condition))
- # Normalisation
- # Dispersion
- # New Neg. Binomial test
- window()
- res <- results(dds)
- # Lets do Anton's regular plots based around raw or log2 transformed data.
- # Effect of Normalisation on counts
- par(mfrow=c(3,1))
- barplot(colSums(counts(dds, normalized=F)), col=as.factor(conds), las=2,cex.names=0.4,main='Pre Normalised Counts')
- legend('center',conds,fill=as.factor(conds),cex=0.6,horiz=TRUE)
- barplot(colSums(counts(dds, normalized=T)), col=as.factor(conds), las=2,cex.names=0.4,main='Post Normalised Counts')
- window()
- heatmap.2(cor(counts(dds,normalized=TRUE)),trace='none',main='Sample to Sample Correlation')
- # Sample PCA
- pca <- princomp(counts(dds,normalized=T))
- plot(pca$loadings, main='Principal Component Analysis', col=colors[pdata$condition], pch=19, cex=2)
- window()
- # They recommend these as alternatives to log2 visualisations.
- # Alternative to Log2 (n+1) transformations - Wolfie and Simon say they are better ?
- vsd <- varianceStabilizingTransformation(dds, blind=TRUE)
- #window()
- #meanSdPlot(assay(rld[notAllZero,]), ylim = c(0,2.5))
- #meanSdPlot(assay(vsd[notAllZero,]), ylim = c(0,2.5))
- select <- order(rowMeans(counts(dds,normalized=TRUE)),decreasing=TRUE)[1:200]
- hmcol <- colorRampPalette(brewer.pal(9, 'GnBu'))(100)
- heatmap.2(counts(dds,normalized=TRUE)[select,], col = hmcol,
- dendrogram='none', trace='none', margin=c(10,6))
- heatmap.2(assay(rld)[select,], col = hmcol,
- dendrogram='none', trace='none', margin=c(10, 6))
- heatmap.2(assay(vsd)[select,], col = hmcol,
- dendrogram='none', trace='none', margin=c(10, 6))
- mat <- as.matrix(distsRL)
- rownames(mat) <- colnames(mat) <- with(colData(dds),
- window()
- heatmap.2(mat, trace='none', col = rev(hmcol), margin=c(13, 13))
- print(plotPCA(rld, intgroup=c('condition')))
- sig_p=0.00001
- z=results(dds)
- hitlist = (abs(z$log2FoldChange) > sig_lfc) & (z$padj <= sig_p) & (!is.na(z$log2FoldChange)) & (!is.na(z$padj))
- window()
- plot(results(dds)$log2FoldChange,-log(results(dds)$padj,10),ylab='-log10(Adjusted P)',xlab='Log2 FoldChange',main='Volcano Plot',pch=19,cex=0.4)
- points(results(dds)[hitlist,'log2FoldChange'],-log(results(dds)[hitlist,'padj'],10),pch=19,cex=0.4,col='red')
- abline(v=-sig_lfc)
- 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))
- dev.off()
barplot2 {gplots} | R Documentation |
Enhanced Bar Plots
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 |
width | optional vector of bar widths. Re-cycled to length thenumber of bars drawn. Specifying a single value will no visibleeffect unless |
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 |
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 |
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 |
beside | a logical value. If |
horiz | a logical value. If |
density | a vector giving the the density of shading lines, inlines per inch, for the bars or bar components.The default value of |
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 |
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 |
axisnames | logical. If |
cex.axis | expansion factor for numeric axis labels. |
cex.names | expansion factor for names. |
inside | logical. If |
plot | logical. If |
axis.lty | the graphics parameter |
offset | a vector indicating how much the bars should be shiftedrelative to the x axis. |
plot.ci | logical. If |
ci.l,ci.u | The confidence intervals (ci.l = lower bound, ci.u =upper bound) to be plotted if |
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 |
plot.grid | if |
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 |
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 if |
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 ( |
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.
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
Author(s)
Original barplot() by R-Core. Enhancements by MarcSchwartz marc_schwartz@comcast.net
See Also
plot(..., type = 'h')
, dotchart
,hist
.