Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log Y-axis in Boxplot in R

Tags:

logging

r

axis

There are 34 variables in my dataset. I am trying to make boxplot for each variable. I also want to use log Y-axis. Here is my R code:

boxplot(mydata,log="y")
#Warning message:
#In plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) :
#  nonfinite axis limits [GScale(-inf,3.61878,2, .); log=1]

Could you please help me how to correct it? Also, I need all variables name in this one figure.

like image 960
user3130644 Avatar asked Jan 13 '14 20:01

user3130644


1 Answers

The problem is that in your "mydata" there are variables containing "0" values. And for zero values the logaritmic rescaling of y-axis provides "-Inf"

log(0)
[1] -Inf

# I tried to reproduce your example:
library(datasets)
data(airquality)

x <- airquality
boxplot(x, log="y") # works fine!

# Now I'm going to manipulate the data by changing the first value of dataset.
x[1,1] <- 0
boxplot(x, log="y")

Warning message:
In plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) :
  nonfinite axis limits [GScale(-inf,2.52375,2, .); log=1]

# To solve this problem I would suggest to replace all "0"-values to 
# "1" values. Why? Because after you want to build log-values, and log(1)=0

x[(x == 0)] <- 1
boxplot(x, log="y") # It works fine!
like image 66
And_R Avatar answered Sep 28 '22 07:09

And_R