gpt4 book ai didi

r - ggplot 为 stat_binhex 设置 bin 位置

转载 作者:行者123 更新时间:2023-12-01 07:48:10 26 4
gpt4 key购买 nike

我想使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com