liamrevell / phytools

GNU General Public License v3.0
198 stars 56 forks source link

Error in plot.window(xlim, ylim, log = log, ...) : need finite 'xlim' values #138

Closed Zoey-Aminah closed 8 months ago

Zoey-Aminah commented 1 year ago

Hi,

I want to produce a barplot next to a plotted tree. But the bars doesn't show.

Below is my code:

library(phytools)

load data

myTree <- ape::read.tree('longname_sptree.newick.tree') GeneCount <- read.csv('Sp_tree_counts.csv')

extract values.

keeps <- c("Counts") Counts = GeneCount[keeps] counts = setNames(Counts)

Plot

plotTree.wBars(myTree,GeneCount$Counts, type = "phylogram",scale = 0.00001) par(mar = c(5.1,4.1,4.1,2.1)) plotTree.barplot(myTree,exp(counts),args.plotTree = list(fsize = 0.5), args.barplot = list(xlab = "counts (mm)"))

And this is the error:

plotTree.barplot(myTree,exp(counts),args.plotTree = list(fsize = 0.5), args.barplot = list(xlab = "counts (mm)")) Error in plot.window(xlim, ylim, log = log, ...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf

My figure is like this:

image

How can I change it? Is that the problem with my data file?

Thank you so much. Regards, Zoey

liamrevell commented 12 months ago

Dear @Zoey-Aminah.

It looks like the problem is the size of your plotting device (and/or the size of the plotting elements, such as the label text). To verify this, try plotting to a large PDF and see if that works. To accomplish this, one normally runs something like the following code:

pdf(file="Rplot.pdf",width=12,height=12)
plotTree.barplot(myTree,exp(counts),args.plotTree = list(fsize = 0.5), args.barplot = list(xlab = "counts (mm)"))
dev.off()

This creates a 12" x 12" PDF figure. You can increase those dimensions as necessary.

-- Liam

Zoey-Aminah commented 11 months ago

Thank you for your help. The issue has been fixed.

Zoey

Liam J. Revell @.***> 于2023年7月12日周三 01:52写道:

Dear @Zoey-Aminah https://github.com/Zoey-Aminah.

It looks like the problem is the size of your plotting device (and/or the size of the plotting elements, such as the label text). To verify this, try plotting to a large PDF and see if that works. To accomplish this, one normally runs something like the following code:

pdf(file="Rplot.pdf",width=12,height=12) plotTree.barplot(myTree,exp(counts),args.plotTree = list(fsize = 0.5), args.barplot = list(xlab = "counts (mm)")) dev.off()

This creates a 12" x 12" PDF figure. You can increase those dimensions as necessary.

-- Liam

— Reply to this email directly, view it on GitHub https://github.com/liamrevell/phytools/issues/138#issuecomment-1631246902, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6QXGP2TJ5GTB7AAL2U7BYLXPWHEFANCNFSM6AAAAAAZRA6ZFQ . You are receiving this because you were mentioned.Message ID: @.***>