我想使用 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 位置。但所有这样做的尝试都没有解决问题。
更新 使用 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))
最佳答案
这是你想要的吗?
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))
关于r - ggplot 为 stat_binhex 设置 bin 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34422013/