Plot large raster in R - r

I've got a large (8GB) raster file that I'd like to plot in R. I try to do the below, but I run out of memory. I'd like some input and ideas on what to do please? Thanks, James.
library(raster)
library(rasterVis)
# ---- setting the colours ------------#
my.at <- c( 0,0.5, 1, 2.5, 5, 10, 15, 20, 25, 30,35,40,45,50, 100, 260)
colours<-c("paleturquoise","lightcyan", "brown","burlywood","bisque2","darkorange2","lightpink",
"darkred","gold1","mediumorchid1","hotpink2", "darkblue","darkblue", "violetred4","violetred4")
pdf("plot_1b.pdf", width=10, height=20)
par(bty='n')
par(mar=c(0, 0,0,0))
plot(raster("2015-06-23_001403_21674_63649.grd"),
xlim=c(-1200000, -650000),
ylim=c(-260000,550000),
maxpixels=445500000000,
breaks=my.at,
col = colours,
lab.breaks=my.at,
legend=FALSE,
axes=FALSE)
dev.off()

Related

How to add logo on levelplot?

I want to make a plot from raster data using levelplot. How to add a header which contains logo.png and title, like showed on this picture?
Here is my data: SST
Here is my basic code to produce this map:
r<-crop(raster(flname, varname="sst"), extent(90, 144, -20, 25))
png('SST.png', height = 2000, width = 2500, res = 300)
print(levelplot(r, col.regions = sst, at=seq(20, 34, 0.1),
yscale.components=yscale.raster.subticks,
xscale.components=xscale.raster.subticks,
margin=FALSE, ylab='Latitude', xlab='Longitude',
main=paste0(flname,' (deg-C)')))
dev.off()
You can use package magick to compose images:
library(rasterVis)
library(magick)
header <- image_read("~/Desktop/headerWithLogo.png")
fig <- image_graph(width = 600, height = 600, res=96)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
levelplot(r, margin=F, main ="Test \n")
dev.off()
out <- image_composite(fig, header, offset = "+50-5")
print(out)

label certain points with textxy()

I am trying to plot a volcano plot in R using the plot function and calibrate package in R and am trying to use the textxy function to plot only certain points.
Here is some data:
Metabolites <- data.frame(Metabolite = c("Glucose", "Galactose", "Creatine", "Lactose", "N-Acetylputrescine", "Tyramine", "Adenine", "Glycine", "Erythritol", "Choline"), Neg_pvalue = c(10, 8, 2, 1, 0.5, 0.7, 5, 3, 5.8, 4), LogFC = c(4, -3, 2, -1, 0.5, 0.7, 1, -2, -4, -1), padjust = c(1.453557e-19, 5.312771e-08, 4.983176e-02, 9.585447e-01, 2.449707e-01, 3.058580e-01, 4.223173e-02, 1.002379e-03, 4.466316e-27, 1.003879e-01))
Here is my code:
with(Metabolites, plot(LogFC, Neg_pvalue, pch=20, main="CNL", xlim=c(-5,6)))
with(subset(Metabolites, padjust <.05 ), points(LogFC, Neg_pvalue, pch=20, col="blue"))`
with(subset(Metabolites, padjust <.05 & abs(LogFC) > 2), points(LogFC, Neg_pvalue, ph=20, col="red"))
Now here is the issue:
with(subset(Metabolites, padjust <.05 & abs(LogFC) > 2), textxy(LogFC, Neg_pvalue, labs=Metabolite[1:3], cex=.5, offset = 0.2))`
If I plot this code, I get only the top 3 data points, as is indicated with the labs=Metabolite[1:3] part of the code. Alternatively, if I plot labs=Metabolite, then I get all labels.
If I wanted to plot the labels of only: Glycine, Lactose, and Erythritol as given in the Metabolites$Metabolite, am I able to do this?
Also, say I wanted to keep my top 3 data points labeled (labs=Metabolite[1:3]), but also want to label other metabolites of interest, say Tyramine and N-Acetylputrescine too; how can I do this?
This seems to work by slecting items that are in that set and using those character values as lables:
library(calibrate)
with(subset(Metabolites, Metabolite %in% c( 'Glycine', 'Lactose', 'Erythritol' )),
textxy(LogFC, Neg_pvalue, labs=c( 'Glycine', 'Lactose', 'Erythritol' ), cex=.5, offset = 0.2))

Plotting with Vennerable package in R

Here is a very basic example:
library(vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
plot(srl.venn)
All I'm trying to do is to remove borders around circles, and format colors and fonts. However, still haven't done much.
Could you please share any useful examples?
Check out VennThemes for changing parameters within the plot. For example:
library(Vennerable)
srl.venn <- Venn(SetNames=c("Cognitive condition","Operations","Individual differences"),
Weight=c(0,30, 21, 15, 1, 8, 3, 6))
srl.venn.c <- compute.Venn(srl.venn, doWeights=T)
gp <- VennThemes(srl.venn.c, colourAlgorithm = "binary")
plot(srl.venn.c, gpList = gp, show = list(FaceText = "signature", SetLabels = FALSE,
Faces = FALSE, DarkMatter = FALSE))
More detail can be found in the man pages or by calling vignette("Venn")

levelplot (R lattice package) with 2 yaxis labels

I want to place 2 sets of y-axis labels on the graph I created using levelplot function from lattice library at R. I was able to get two sets of labels to show but they are overlapping. Below please see a minimum example. I also tried a few options at par.settings such as ylab.axis.padding and axis.components padding, but nothing seemed to change the superimposition of 2 y-labels. Perhaps they have been overwritten somehow? Any ideas will be appreciated.
My example codes :
A = matrix( c(3, 1, 0, 1, 2, 3, 1, 0,
rep(1,4), 2, 0, 1), nrow=3, ncol=5, byrow = TRUE)
colnames(A)= c("XXX5", "XXX4", "XXX3", "XXX2", "XXX1")
axis.build=function(side,...){
if(side == "left"){
panel.axis(side=side, outside=TRUE, at=1:5,tck=0,
text.col="black", labels=colnames(A), text.cex=0.5)
panel.axis(side=side, outside=TRUE, at=1:5,tck=0,
text.col="brown", labels=seq(ncol(A)), text.cex=0.9 )
} else axis.default(side=side, ...)
}
levelplot(A, aspect="iso", shrink = c(0.8, 0.8),
scales= list(x=list(draw=F),cex=0.5, font=2),
axis=axis.build,, xlab= NULL, ylab=NULL,
col.regions=c("black", "orange", "red","purple"),
at=c(-1, 0, 1, 2, 3), colorkey = FALSE,
par.settings = list(axis.line=list(col="transparent"),
axis.components=list(bottom=list(pad1=1, pad2=3)) ))
I think I have found the solution. In case anyone interested : I changed the first tck=0 to tck=2, and added line.col= "transparent", thus two left axis are stacked next to each other. Voila ! However, I can't seem to find where the documentation is for using pad1 and pad2 parameters. Any suggestion?

Is there a way to turn off clustering when using the R pheatmap package?

I have created a matrix and now I would like to use pheatmap to draw a heatmap while preserving the order of the matrix rows. I would like to turn clustering off. Currently, pheatamp is clustering the rows when I run the following script:
tissuedata<-read.table('OrderedByGeneCounts.csv', header=TRUE, sep=',')
tissuedata2<-data.matrix(tissuedata)
tissuedata3<-log10(tissuedata2)
is.na(tissuedata3) <- do.call(cbind,lapply(tissuedata3, is.infinite))
tissuedata3[is.na(tissuedata3)] <- 0
tissue_exons<-scan(file="OrderedExonsList.txt", what="character", strip.white=TRUE)
rownames(tissuedata3)<-tissue_exons
pdf(file="pheatmapENSG00000026025.pdf", paper="a4", height=15)
pheatmap(tissuedata3,
color = colorRampPalette(rev(c("#D73027", "#FC8D59", "#FEE090", "#FFFFBF", "#E0F3F8", "#91BFDB", "#4575B4")))(100),
cellwidth = 25, cellheight = 3.8,
treeheight_row = 0,
treeheight_column=0,
kmeans_k = NA,
show_rownames = T, show_colnames = T,
fontsize=4,
scale="none",
legend=FALSE,
)
dev.off()
pheatmap(..., cluster_rows=FALSE, cluster_cols=FALSE) in general, as per #blmoore

Resources