R 什么是;正在塌陷为唯一';x';价值观;在这个例子中是什么意思?
下面的示例图显示了一条关于R 什么是;正在塌陷为唯一';x';价值观;在这个例子中是什么意思?,r,ggplot2,unique,warnings,R,Ggplot2,Unique,Warnings,下面的示例图显示了一条关于 In regularize.values(x, y, ties, missing(ties), na.rm = na.rm) : collapsing to unique 'x' values 在我的例子中,我无法理解这意味着什么 它必须与5相关,因为用4或1替换5时,警告消失 df <- data.frame(x = 1, y = c(0, 0.25, 0.5, 0.75, 5)) ggplot2::ggplot(df, ggplot2::aes(x =
In regularize.values(x, y, ties, missing(ties), na.rm = na.rm) :
collapsing to unique 'x' values
在我的例子中,我无法理解这意味着什么
它必须与5
相关,因为用4
或1
替换5
时,警告消失
df <- data.frame(x = 1, y = c(0, 0.25, 0.5, 0.75, 5))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5))
df@teunbrand证实了我的假设
ecdf <- stats::approxfun(dens, data$y)
注意:由于使用dens
作为累积密度等细节,该代码很难读取
但是stats::regularize.values
并不一定更好:
x <- xy.coords(x, y) # -> (x,y) numeric of same length
y <- x$y
x <- x$x
x(x,y)相同长度的数值
我很想知道答案。然而,我注意到删除draw_quantiles=c(0.5)
也会停止警告;所以我在想,这个论点可能与5
离群值有某种问题?@艾里科帕托是的,我倾向于最小化我的代码示例-任何留在里面的东西都是相关的draw_quantiles=c(0.5)
如果不重要的话就不会在那里;)我已经提交了文件,我认为问题在于,估计密度作为x
传递到stats::approxfun
stats::approxfun
,依次关注x
中的关系。因此,问题似乎是df$y
中的远异常值导致了零密度,从而导致了平坦的累积密度。我可以想象,ecdf是的,我得出了与@bers相同的结论。打印密度(df$y)$y
将在第282个元素周围显示一段零。还有一种方法建议根据观测值而不是密度来计算分位数。
x <- xy.coords(x, y) # -> (x,y) numeric of same length
y <- x$y
x <- x$x
ecdf <- stats::approxfun(dens, data$y, ties = "ordered")
create_quantile_segment_frame <- function(data, draw_quantiles) {
dens <- cumsum(data$density) / sum(data$density)
ecdf <- stats::approxfun(dens, data$y, ties = "ordered")
ys <- ecdf(draw_quantiles) # these are all the y-values for quantiles
# Get the violin bounds for the requested quantiles.
violin.xminvs <- (stats::approxfun(data$y, data$xminv))(ys)
violin.xmaxvs <- (stats::approxfun(data$y, data$xmaxv))(ys)
# We have two rows per segment drawn. Each segment gets its own group.
ggplot2:::new_data_frame(list(
x = ggplot2:::interleave(violin.xminvs, violin.xmaxvs),
y = rep(ys, each = 2),
group = rep(ys, each = 2)
))
}
assignInNamespace("create_quantile_segment_frame", create_quantile_segment_frame, "ggplot2")
df <- data.frame(x = 1, y = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), bw = 0.1)