Hi, it is just a simple barchart or bar-plot. First, create a data-frame that has your GO enrichment terms as rows and count values in a single column, like this:
input
GO1 128
GO2 1
GO3 70
GO4 6
GO5 17
GO6 14
GO7 18
GO8 4
GO9 13
GO10 0
GO11 0
GO12 5
GO13 16
GO14 5
GO15 2
GO16 0
GO17 0
GO18 20
GO19 6
GO20 0
GO21 0
GO22 0
GO23 2
GO24 0
GO25 6
GO26 1
GO27 5
GO28 1
GO29 0
GO30 0
GO31 0
GO32 0
GO33 1
Then, generate separate barcharts with lattice and piece them together on the same panel using grid / gridExtra:
require(lattice)
require(RColorBrewer)
require(rasterVis)
require(gridExtra)
require(grid)
A <- barchart(
data.matrix(input[1:15,]),
col="black",
xlab="Total count", ylab="",
pretty=TRUE,
scales=list(
x=list(cex=1.0, col="black", fontface="bold"),
y=list(cex=0.8, labels=rownames(input), col="black", fontface="bold"),
xlab=list(cex=2.0),
ylab=list(cex=2.0),
tck=c(1,0)),
aspect="fill")
B <- barchart(
data.matrix(input2[1:15,]),
col="black",
xlab="Total count", ylab="",
pretty=TRUE,
scales=list(
x=list(cex=1.0, col="black", fontface="bold"),
y=list(cex=0.8, labels=rownames(input2), col="black", fontface="bold"),
xlab=list(cex=2.0),
ylab=list(cex=2.0),
tck=c(1,0)),
aspect="fill")
layout <- cbind(c(1,2))
grid.arrange(
layout_matrix=layout,
arrangeGrob(A,
top=textGrob("A",
x=unit(0.05,"npc"),
y=unit(0.9,"npc"),
just=c("left","top"),
gp=gpar(fontsize=32))),
arrangeGrob(B,
top=textGrob("B",
x=unit(0.05,"npc"),
y=unit(0.9,"npc"),
just=c("left","top"),
gp=gpar(fontsize=32))),
ncol=1)
------------------------------------------------------------
For side to side, alter the layout and use ncol=2 to grid.arrange
A <- barchart(
data.matrix(input),
col="black",
xlab="Total count", ylab="",
pretty=TRUE,
scales=list(
x=list(cex=1.0, col="black", fontface="bold"),
y=list(cex=0.8, labels=rownames(input), col="black", fontface="bold"),
xlab=list(cex=2.0),
ylab=list(cex=2.0),
tck=c(1,0)),
aspect="fill")
B <- barchart(
data.matrix(input2),
col="black",
xlab="Total count",
ylab="",
pretty=TRUE,
scales=list(
x=list(cex=1.0, col="black", fontface="bold"),
y=list(cex=0.8, labels=rownames(input2), col="black", fontface="bold"),
xlab=list(cex=2.0),
ylab=list(cex=2.0),
tck=c(1,0)),
aspect="fill")
layout <- cbind(c(1),c(2))
grid.arrange(
layout_matrix=layout,
arrangeGrob(A,
top=textGrob("A",
x=unit(0.05,"npc"),
y=unit(0.9,"npc"),
just=c("left","top"),
gp=gpar(fontsize=32))),
arrangeGrob(B,
top=textGrob("B",
x=unit(0.05,"npc"),
y=unit(0.9,"npc"),
just=c("left","top"),
gp=gpar(fontsize=32))),
ncol=2)
Hello Kevin Blighe,
Thank you sir for the solution. and I'm so sorry that i didn't check your reply. Your answer is very helpful thank so much.
No problem my dear Sir / Madam
Hello,
May I kindly ask you to let me know how can I also add to the above bar chart a vertical red line which shows a threshold (such as for example 0.05 p-value as a threshold of significance). I need to create a bar chart like the attached figure.
I assume that the red line, in the attached image, shows -log10(0.05) threshold which is equal to 1.30103. Am I right? I would highly appreciate if you can let me know how to add this threshold red line to my bar chart. Many thanks.
Hey, I presume that you can add a red line via
abline(v = ..., col = 'red2', lwd = 2)
, i.e., after you have already calledbarplot()
Thank you so much for your guide. As you suggested, I did as below, but faced with the below Error:
I would highly appreciate if you can help me what I did wrong and how to solve it to have a vertical line (at 1.30103 x-axis) on both of my bar plots. Many thanks.
Hey, I am not sure... can you paste a sample of
data.matrix(GSEA_data_GO)
?I have also tidied my own code in my original answer, which may help for debugging purposes.
Thanks for your reply. I got as below:
Thank you.
Oh, but, to what does V1 and V2 relate? If you look at my data-input, I only have a single column of values (the other, comprising the labels Go1, Go2, etc, are set as rownames).
I have a GSEA_data_GO.csv file that has only two columns (without column name). The first column contains the Gene Set Enrichment terms, and second column contains values for each Gene Set Enrichment term. The same for GSEA_data_KEGG.csv file.
I read GSEA_data_GO.csv and GSEA_data_KEGG.csv files into R using:
After loading my datasets into R, when I called for example GSEA_data_GO , I found that R made column names as V1 and V2 for my columns by itself, while I did not have any column names in my csv files.
Okay, then you probably need to do something like:
Also, do you need
header=FALSE
? Always look inside your files and also look at them after you have read them in. Try to also get into the habit of using thestr()
function so that you can see how your objects are structured and encoded, which is particularly relevant for data-frames.Thank you very much for your guide Kevin. I simplified my example as below:
and I got the bar chart but in y-axis, instead of having GO10...GO15, I have 1, 2, 3, 4, 5, 6. Also again when I run abline I faced the below error :(
I can not see what is wrong even in a very simple dataset that can not put rownames as y-axis and also can not run abline.
Sorry I sent my reply two times mistakenly.