简体   繁体   English

在R中的Boxplot中记录Y轴

[英]Log Y-axis in Boxplot in R

There are 34 variables in my dataset. 我的数据集中有34个变量。 I am trying to make boxplot for each variable. 我正在尝试为每个变量制作boxplot。 I also want to use log Y-axis. 我也想使用log Y轴。 Here is my R code: 这是我的R代码:

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. 另外,我需要在这个图中的所有变量名称。

The problem is that in your "mydata" there are variables containing "0" values. 问题是在你的“mydata”中有变量包含“0”值。 And for zero values the logaritmic rescaling of y-axis provides "-Inf" 对于零值,y轴的logaritmic重新缩放提供“-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!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM