我想要用两个轴的对数刻度绘制这两个分布:
library(ggplot2)
set.seed(99)
data <- data.frame(vec1 = as.integer(rlnorm(10000, sdlog = 2)),
vec2 = as.integer(rlnorm(10000, sdlog = 2)))
我可以使用geom_point()
ggplot(data, aes(vec1, vec2)) + geom_point() + scale_x_log10() + scale_y_log10()
但不是stat_binhex()
ggplot(data, aes(vec1, vec2)) + stat_binhex() + scale_x_log10() + scale_y_log10()
会产生错误
Error in if (!missing(xbnds) && any(sign(xbnds - range(x)) == c(1, -1))) stop("'xbnds' must encompass range(x)") :
missing value where TRUE/FALSE needed
有可能吗?
答案 0 :(得分:0)
按照Didzis Elferts'指示关闭问题(@ Didzis Elferts',如果您愿意,请随时回复我的回答)。代码如下。
…
ggplot(data, aes(vec1+1, vec2+1)) + stat_binhex() + scale_x_log10() + scale_y_log10()
或者,您可以删除0
值
bar <- subset(data, vec1 != 0 & vec2 != 0)
ggplot(bar, aes(vec1, vec2)) + stat_binhex() + scale_x_log10() + scale_y_log10()