Boxplot's input Y axis in R

There are 34 variables in my dataset. I am trying to make boxplot for each variable. I also want to use the Y-axis log. 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 help me how to fix this? In addition, I need the name of all the variables in this figure.

+5
source share
1 answer

The problem is that there are variables in your "mydata" that contain "0" Values. And for zero values, the logarithmic scaling of the 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!
+6
source

All Articles