Related
I'm using VennDiagram to illustrate the overlap between distinct sets of customers -- in total and for a particular sub-segment. The problem that I'm having is that it appears VennDiagram automatically orders the circles in the output from largest to smallest. In the two diagrams I'm creating the relative size of the two populations is flipping, so in the output the populations/colors of the diagram are reversed. I want to put these side by side in a document, and the flipping of population order makes side by side comparison a little confusing.
Sample code for each is below -- is there a way to manually force the ordering of sets in the output, so that populations are ordered in the same sequence?
Thank you -
venn.plot <- venn.diagram(
x = list(
"AD" = 1:703814,
"WM" = 672279:1086933
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Total.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Total Populations",
main.cex = 2,
sub.cex = 1.5
);
venn.plot <- venn.diagram(
x = list(
"AD" = 1:183727,
"WM" = 173073:383052
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Target.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Target Populations",
main.cex = 2,
sub.cex = 1.5
);
use an if statement to see if the second set is larger than the first. if yes, then add 180 degrees to rotation.
It can be solved by altering the gList object from draw.pairwise.venn() function. venn.diagram() is a wrapper for many draw.____.venn() functions (Eg: pairwise, quad, quintuple, single etc.,)
Use an if statement to find any switch in the labels of population in your example. If true, then change inverted = TRUE and switch labels.
Also use ind = FALSE to prevent drawing the diagram.
I used your example to show solution for one of two venn diagrams you posted in your question.
packageVersion("VennDiagram")
# [1] ‘1.6.17’
AD <- 1:703814
WM <- 672279:1086933
overlap <- calculate.overlap(x = list('AD' = AD, 'WM' = WM))
area_overlap <- sapply(overlap, length)
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = FALSE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# check for switch in labels
if(area_overlap[1] != (as.integer(g[[5]]$label) + as.integer(g[[7]]$label)) && area_overlap[2] != (as.integer(g[[6]]$label) + as.integer(g[[7]]$label))){
# change inverted to TRUE
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = TRUE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# switch labels
tmp_var <- g[[6]]$label
g[[6]]$label <- g[[5]]$label
g[[5]]$label <- tmp_var
rm(tmp_var)
}
jpeg("AD_vs_WM_Total_new.jpg", width = 1200, height = 1200)
plot.new()
title(main = "AD vs. WM", sub = "Total Populations", cex.main = 6, cex.sub = 5, line = -4, outer = TRUE)
grid.draw(g)
dev.off()
If statement would do the trick but it seems a bit heavy handed for such a small task. I think you could simply add the following line into your script
inverted=length(x$AD) < length(x$WM)
And that should do the trick (when WM is longer than AD statement is True and plot is inverted).
This didn't work for me. The data in the circles flipped, but the labels on the circles stayed in place. The rotation approach worked, though.
I have used the following for creating a Heatmap:
par(mar = c(6, 8.5, 3, 3));
labeledHeatmap(Matrix = moduleTraitCor,
xLabels = colnames(datTraits),
yLabels = names(MEs),
ySymbols = names(MEs),
colorLabels = FALSE,
cex.lab = 1.0,
cex.lab.x = 0.7,
cex.lab.y = 0.7,
xColorWidth = 0.01,
yColorWidth = 0.02,
colors = greenWhiteRed(83),
textMatrix = NULL,
setStdMargins = FALSE,
cex.text = NULL,
zlim = c(-1,1),
margins =c(12,9))
And got:
I want to decrease the height of each cell by y-axis. It is a large Heatmap, any suggestions to make it better will be helpful. Thank you!
I like the package EnhancedVolcano. My data is RNAseq and I analyse it with DESeq2. I want to plot the results as a volcanoplot where I highlight a list of genes of my choice picked_genes. I have succeded in changing pointSize and I am using SelectLab to highlight but when I want to give the chosen genes another color I get stuck. I have added a logical vector to my results file specifying which genes to highlight. I have tried
col = ifelse...
It doesn't work, all dots are grey.
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
col = (ifelse(res_complete$picked_genes == T, "forestgreen", "grey60")),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
selectLab = picked_genes,
shape = 16,
shade = res_complete$picked_genes == T,
shadeFill = "forestgreen",
shadeSize = 5,
shadeLabel = res_complete$picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
I have also tried:
colCustom =ifelse...
But I get an error message...
Error: Aesthetics must be either length 1 or the same as the data (58735): colour
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
colCustom = (ifelse(res_complete$picked_genes == T, "forestgreen", "grey60")),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
selectLab = picked_genes,
shape = 16,
shade = res_complete$picked_genes == T,
shadeFill = "forestgreen",
shadeSize = 5,
shadeLabel = res_complete$picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
Can someone come up with a solution to this problem?
I found it, finally I understood it. colCustom needs a pair for each point, a color and a name. I created the matrix keyvals
keyvals <- ifelse(
res_complet$picked_genes < T, 'grey60',
'forestgreen')
names(keyvals)[keyvals == 'forestgreen'] <- 'picked'
names(keyvals)[keyvals == 'grey60'] <- 'rest'
`
Than I used it to replace the col=
`
EnhancedVolcano(res_complete,
lab = res_complete$gene_name,
x = "log2FoldChange",
y = "pvalue",
pCutoff = 10e-3,
FCcutoff = 1,
xlim = c(-10, 10),
ylim = c(0, -log10(10e-12)),
pointSize = (ifelse(res_complete$picked_genes == T, 5, 0.5)),
labSize = 2.5,
shape = c(19, 19, 19, 19),
selectLab = picked_genes,
boxedLabels = TRUE,
title = "DESeq2 results",
subtitle = "Differential expression HC vs RA",
caption = "FC cutoff, 1; p-value cutoff, 10e-3",
legendPosition = "right",
legendLabSize = 14,
colCustom = keyvals,
colAlpha = 0.9,
drawConnectors = TRUE,
hline = c(10e-8),
widthConnectors = 0.2)
`
In order to get all points visible I sorted my results dataframe after the logical column res_complete$picked_genes and made the volcano again. Voilá
I'm using VennDiagram to illustrate the overlap between distinct sets of customers -- in total and for a particular sub-segment. The problem that I'm having is that it appears VennDiagram automatically orders the circles in the output from largest to smallest. In the two diagrams I'm creating the relative size of the two populations is flipping, so in the output the populations/colors of the diagram are reversed. I want to put these side by side in a document, and the flipping of population order makes side by side comparison a little confusing.
Sample code for each is below -- is there a way to manually force the ordering of sets in the output, so that populations are ordered in the same sequence?
Thank you -
venn.plot <- venn.diagram(
x = list(
"AD" = 1:703814,
"WM" = 672279:1086933
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Total.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Total Populations",
main.cex = 2,
sub.cex = 1.5
);
venn.plot <- venn.diagram(
x = list(
"AD" = 1:183727,
"WM" = 173073:383052
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Target.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Target Populations",
main.cex = 2,
sub.cex = 1.5
);
use an if statement to see if the second set is larger than the first. if yes, then add 180 degrees to rotation.
It can be solved by altering the gList object from draw.pairwise.venn() function. venn.diagram() is a wrapper for many draw.____.venn() functions (Eg: pairwise, quad, quintuple, single etc.,)
Use an if statement to find any switch in the labels of population in your example. If true, then change inverted = TRUE and switch labels.
Also use ind = FALSE to prevent drawing the diagram.
I used your example to show solution for one of two venn diagrams you posted in your question.
packageVersion("VennDiagram")
# [1] ‘1.6.17’
AD <- 1:703814
WM <- 672279:1086933
overlap <- calculate.overlap(x = list('AD' = AD, 'WM' = WM))
area_overlap <- sapply(overlap, length)
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = FALSE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# check for switch in labels
if(area_overlap[1] != (as.integer(g[[5]]$label) + as.integer(g[[7]]$label)) && area_overlap[2] != (as.integer(g[[6]]$label) + as.integer(g[[7]]$label))){
# change inverted to TRUE
g <- draw.pairwise.venn(area1 = area_overlap[1],
area2 = area_overlap[2],
cross.area = area_overlap[3],
category = c("AD", "WM"),
ind = FALSE,
inverted = TRUE,
scaled = TRUE,
ext.text = TRUE,
lwd = 1,
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 6,
cat.cex = 6,
cat.col = c("black", "black"),
cat.dist = c(-0.16, -0.09),
cat.pos = c(0,10),
rotation.degree = 35)
# switch labels
tmp_var <- g[[6]]$label
g[[6]]$label <- g[[5]]$label
g[[5]]$label <- tmp_var
rm(tmp_var)
}
jpeg("AD_vs_WM_Total_new.jpg", width = 1200, height = 1200)
plot.new()
title(main = "AD vs. WM", sub = "Total Populations", cex.main = 6, cex.sub = 5, line = -4, outer = TRUE)
grid.draw(g)
dev.off()
If statement would do the trick but it seems a bit heavy handed for such a small task. I think you could simply add the following line into your script
inverted=length(x$AD) < length(x$WM)
And that should do the trick (when WM is longer than AD statement is True and plot is inverted).
This didn't work for me. The data in the circles flipped, but the labels on the circles stayed in place. The rotation approach worked, though.
When creating a table using tableGrob or grid.table.
Is there way to align the text inside the table? First column to the left, and the other columns to the right? Rather than the default "center".
Thank you!
something like this: where I want column "a" alligned to the left.
a <- c("one","two","thirty five")
b <- c(1, 2, 3)
c <- c(4, 5, 6)
data <- data.frame(a,b,c)
windows()
grid.table(
data,
gpar.coretext=gpar(fontsize = 12),
gpar.coltext = gpar(fontsize = 12),
gpar.rowtext = gpar(fontsize = 12),
gpar.corefill =
gpar(fill = "green", alpha = 0.5, col = NA),
h.even.alpha = 0.5,
equal.width = FALSE,
show.rownames = FALSE,
show.vlines = TRUE,
padding.h = unit(15, "mm"),
padding.v = unit(8, "mm")
)
With gridExtra v>=2.0.0, the parameters are now controlled via nested lists (themes),
library(gridExtra)
library(grid)
n=5
d <- data.frame(x=rnorm(n),y=rnorm(n),z=sample(letters[1:2],n,replace=T))
m <- format(d, digits = 1, scientific=F,big.mark = ",")
mytheme <- ttheme_default(core = list(fg_params = list(hjust=0, x=0.1,
fontsize=8)),
colhead = list(fg_params = list(fontsize=9,
fontface="bold"))
)
g1 <- tableGrob(m, theme = mytheme, rows=NULL)
grid.newpage()
grid.draw(g1)
Is this what you are looking for? There is a core.just parameter of the format() call.
require("gridExtra")
n=5
df<- data.frame(x=rnorm(n),y=rnorm(n),z=sample(letters[1:2],n,replace=T))
g1<-tableGrob(
format(df, digits = 1,
scientific=F,big.mark = ","),
core.just="left",
#core.just="right",
#col.just="right",
gpar.coretext=gpar(fontsize=8),
gpar.coltext=gpar(fontsize=9, fontface='bold'),
show.rownames = F,
h.even.alpha = 0,
gpar.rowtext = gpar(col="black", cex=0.7,
equal.width = TRUE,
show.vlines = TRUE,
show.hlines = TRUE,
separator="grey")
)
grid.draw(g1)
To set a "transparent" background, use the ttheme_minimal with hjust to set text alignment.
theme_1 <- ttheme_minimal(core = list(fg_params = list(hjust = 0,
x = 0.1,
fontsize = 9)),
colhead = list(fg_params = list(fontsize = 12,
fontface = "bold")))
You can then apply the theme to the tableGrob like this:
gridExtra::tableGrob(df_tbl, theme = theme_1, rows=NULL)