conditional loop does not work for plotting in R !!
1
0
Entering edit mode
9.0 years ago
unique379 ▴ 120

Dear all,

I am trying to use function from clusterProfiler and DOSE packages and made a conditional loop for plotting. It seems it does not work properly (plot only last one), why I really dont figure it out. Please help.

ont="DO"

## this does not work ?? plot only enrichMap, why?

if (ont=="DO") {
  pdf("DO.plots1.pdf",width=11,height=8.5)
  barplot(enrich_go_do, drop=T, showCategory = 30, title = "Disease Ontology")
  # altrneative of barplot
  dotplot(enrich_go_do, x = "geneRatio", colorBy = "p.adjust", showCategory = 10, title = "Disease Ontology (Category 10)")
  enrichMap(enrich_go_do,n = 10) # topten
  dev.off()
}

## this works perfectly
pdf("DO.plots2.pdf",width=11,height=8.5)
# # Disease Ontology plots
barplot(enrich_go_do, drop=T, showCategory = 30, title = "Disease Ontology")
# altrneative of barplot
dotplot(enrich_go_do, x = "geneRatio", colorBy = "p.adjust", showCategory = 10, title = "Disease Ontology (Category 10)")
enrichMap(enrich_go_do,n = 10) # topten
dev.off()
R • 4.2k views
ADD COMMENT
0
Entering edit mode

What do you mean by "plot only last one"? Does it produce only one graph for the whole for-loop? Or that without if it plots?

ADD REPLY
0
Entering edit mode

yes its processed only one plot out of 3 plot given.

ADD REPLY
0
Entering edit mode

Thank you guys..problem solved.

it was needed print(barplot()). The reason was author has made barplot function using ggplot2.

ADD REPLY
0
Entering edit mode

I stuck on this problem for several hours. Yes. print(barplot()) and print(dotplot()) work fine.

ADD REPLY
1
Entering edit mode
9.0 years ago

You open a PDF file to write to, and override it on every iteration by the looks of things. Try using a for loop and changing the filename for each iteration.

ADD COMMENT
0
Entering edit mode

as this not gonna work.....you have seen without loop its work perfectly. However, i used PostScript function inside same loop (if), which produces separate file name for each plot (plot%03d). Therefore in this case, alos does not work...results is the same. only one plot i got at the last.

ADD REPLY

Login before adding your answer.

Traffic: 1928 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6