Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying xlim and ylim when using log-scale in R

Tags:

plot

r

I'm trying to specify the lower and upper range for the x- and y-axis for a log-scale plot. I thought I could use xlim and ylim, but I receive a warning message and no plot:

1: In plot.window(...) : nonfinite axis limits [GScale(-inf,3.30103,1, .); log=1]

Here is my code.

plot(FAS_set$ConcCalc~ZCS_set$ConcCalc,pch=21,bg="black",log="xy",xlim=c(0,2000),ylim=c(0,100000))

Any help would be appreciated.

Cheers.

like image 349
sinclairjesse Avatar asked Feb 11 '11 17:02

sinclairjesse


People also ask

How do you plot a log scale in R?

To create a Log-Log plot in base R we pass log(data) as data argument instead of data in the plot() function. The log() function converts the data value into its logarithmic value. The log() function by default calculates the natural logarithms.

What does YLIM mean in Rstudio?

Let's start with the ylim() function. It specifies the upper and lower limit of the y-axis. It is a fundamental function and can be used inside the ggplot() , plot() , and other plot functions as a parameter.


1 Answers

On a log-scale, 0 is minus infinity. Change your lower limit to 0.000001 or something and you'll be fine, eg this works:

 plot(1:10, xlim=c(0.001,10), ylim=c(0.001,10), log="xy")
like image 80
Dirk Eddelbuettel Avatar answered Sep 26 '22 02:09

Dirk Eddelbuettel