r - ggplot 为 stat_binhex 设置 bin 位置

标签 r ggplot2

我想使用 stats_binhex 生成两个“重叠”图

这个想法是第一个二进制六边形图显示数据的潜在位置。这是为了说明数据的“域”。第二个 binhex 然后显示所选数据。 但是,如果我从 y 范围中过滤掉数据,叠加图会奇怪地扭曲

data <- mtcars
subdata<-data[which(data["disp"]>200),]
ggplot(subdata)+
   stat_binhex(data=data,
               fill="white",
               aes(x=mpg,y=disp))+
   stat_binhex(aes(x=mpg,y=disp))

我有一种感觉,我必须设置 bin 位置。但所有这样做的尝试都没有解决问题。

问题说明:https://pl.vc/4kinz

更新 使用 MLavoie 下面提供的提示,可以做得更好一些,但是,中心区域仍然扭曲并且性能受到负面影响

plot.fun <- function(data,selector){
  print(max(data[-selector,"Sepal.Length"]))
  ggplot(data[selector,])+
     stat_binhex(data=data[-selector,],fill="white",aes(y=Sepal.Length,x=Sepal.Width))+
     stat_binhex(aes(y=Sepal.Length,x=Sepal.Width))
 }


   plot.fun(iris,which(data["Sepal.Length"]>6))

Version 2 on iris

最佳答案

这是你想要的吗?

data <- mtcars
subdata<-data[which(data["disp"]>200),]; subdata2<-data[which(data["disp"]<200),]
ggplot(subdata)+
   stat_binhex(data=subdata2,
               fill="white",
               aes(x=mpg,y=disp))+
   stat_binhex(aes(x=mpg,y=disp))

enter image description here

关于r - ggplot 为 stat_binhex 设置 bin 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34422013/

相关文章:

r - 填充区域以匹配网格中各种 'type' 参数的行

r - 将文本大小映射到 ggplot 中的数据的策略

RSelenium 无法连接到主机 rsDriver()

r - 如何用文本和上标ggplot2编写x轴标题

r - 在带有 ggplot2 的条形图旁边

r - 在 ggplot2 中用 facets 绘制分布的分位数

R - dplyr - 运行许多非常相似的查询的代码......?

R混淆矩阵敏感性和特异性标记

r - 如何显示趋势线的图例?

将线旋转到真北或垂直