gpt4 book ai didi

r - R中Boxplot中的对数Y轴

转载 作者:行者123 更新时间:2023-12-04 10:08:15 24 4
gpt4 key购买 nike

我的数据集中有 34 个变量。我正在尝试为每个变量制作箱线图。我也想使用 log Y Axis 。这是我的 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]

你能帮我如何纠正它吗?另外,我需要这个图中的所有变量名称。

最佳答案

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

关于r - R中Boxplot中的对数Y轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21101169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com