带有抖动地毯的直方图
Histogram with a jittery rug
以下脚本
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
制作这张漂亮的照片:
但其中许多蓝线重叠。我想添加一些抖动!我试过使用:
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
调用中将 y 设为 0,它将绘制一切正常:
p + geom_rug(sides = "b", aes(y = 0), position = "jitter", colour = "blue")
使用一些更明显的数据:
dat <- c(rep(1, 50), rep(2, 50))
dat <- data.frame(dat)
无抖动:
有抖动:
以下脚本
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
制作这张漂亮的照片:
但其中许多蓝线重叠。我想添加一些抖动!我试过使用:
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
调用中将 y 设为 0,它将绘制一切正常:
p + geom_rug(sides = "b", aes(y = 0), position = "jitter", colour = "blue")
使用一些更明显的数据:
dat <- c(rep(1, 50), rep(2, 50))
dat <- data.frame(dat)
无抖动:
有抖动: