我有以下代码
library("ggplot2")
library("scales")
set.seed(100)
df <- data.frame(test = rexp(1000, 1))
p <- ggplot(df, aes(x = test)) + geom_histogram(colour="black", fill="#FF9999",
binwidth = ((range(df$test)[2] - range(df$test)[1])/10))
p
正如您所看到的,我使用范围的第10个binwidth
而不是范围的默认binwidth / 30(实际上在帮助中推荐更改此值)。现在使用这种数据,p + scale_x_log10()
的日志转换效果很好,但是当我尝试使用其他变量(实际上是真实变量而不是随机生成的)时,我经常会收到错误(翻译自德语)< / p>
Error in seq.default(min, max, by = by) :
invalid (to - from)/by in seq(.)
这是什么意思?我是否使用正确和推荐的技术根据数据范围更改binwidth?