在R中的Boxplot中记录Y轴

时间:2014-01-13 20:55:46

标签: r logging axis

我的数据集中有34个变量。我正在尝试为每个变量制作boxplot。我也想使用log Y轴。这是我的R代码:

  

箱线图(MYDATA,登录= “y”)的   警告信息:   在plot.window中(xlim = xlim,ylim = ylim,log = log,yaxs = pars $ yaxs):     非限定轴限制[GScale(-inf,3.61878,2 ,.);日志= 1]

你能帮我解决一下吗?另外,我需要在这个图中的所有变量名称。谢谢你!

1 个答案:

答案 0 :(得分:6)

问题是在你的“mydata”中有变量包含 “0”值。对于零值,y轴的对数重新缩放 提供“-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!