gpt4 book ai didi

r - 带有抖动地毯的直方图

转载 作者:行者123 更新时间:2023-12-04 18:37:21 25 4
gpt4 key购买 nike

下面的脚本

library(ggplot2)
dat<-rnorm(80)
dat<-data.frame(dat)
p<-ggplot(dat, aes(x=dat))+geom_histogram()
p<-p+geom_rug(sides="b", colour="blue")
p

使这张漂亮的照片:

Histogram with a rug

但其中许多蓝线重叠。我想添加一些抖动!我试过使用:
p<-p+geom_rug(sides="b", position="jitter", colour="blue")

但是我收到了一条错误消息:

stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. Error: position_jitter requires the following missing aesthetics: y


y直方图的坐标是直方图应该自动生成的计数。

我怎样才能得到我的紧张?

最佳答案

您可以简单地在 aes 中给出 0 的 y调用,它会绘制一切正常:

p + geom_rug(sides = "b", aes(y = 0), position = "jitter", colour = "blue")

使用一些更明显的数据:
dat <- c(rep(1, 50), rep(2, 50))
dat <- data.frame(dat)

无抖动:

enter image description here

有抖动:

enter image description here

关于r - 带有抖动地毯的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32468772/

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