Question: conditional loop does not work for plotting in R !!
0
gravatar for unique379
3.4 years ago by
unique37970
Spain
unique37970 wrote:

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 • 1.6k views
ADD COMMENTlink modified 3.4 years ago • written 3.4 years ago by unique37970

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 REPLYlink written 3.4 years ago by Anton Shekhov60

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

ADD REPLYlink written 3.4 years ago by unique37970
1
gravatar for andrew.j.skelton73
3.4 years ago by
London
andrew.j.skelton735.7k wrote:

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 COMMENTlink written 3.4 years ago by andrew.j.skelton735.7k

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 REPLYlink written 3.4 years ago by unique37970
0
gravatar for unique379
3.4 years ago by
unique37970
Spain
unique37970 wrote:

Thank you guys..problem solved.

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

ADD COMMENTlink written 3.4 years ago by unique37970

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

ADD REPLYlink written 18 months ago by ken.sd.hsu0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 910 users visited in the last hour