我想繪製我的數據在ggplot與使用點。它創建該地塊: 在stat_binhex R日誌規模
正如你可以看到,這是不好的,所以我決定用對數刻度,以獲得更好的結果,我的數據爲0的創造無限的。我用這個腳本將無限轉換爲0;
test.data$d.log[is.infinite(test.data$d.log)] <- 0
test.data$f.log[is.infinite(test.data$f.log)] <- 0
test.data=test.data[complete.cases(test.data), ]
和我的數據(test.data)看起來像這樣;
friend_ratio degree_ratio f.log d.log
oncevatan81 0.7763884 23.66667 -0.25310235 3.164068
hatunkotu 0.4991004 0.00000 -0.69494803 0.000000
TwitineGeldim 0.9838102 45.00000 -0.01632226 3.806662
Kralice_Hanim 0.9278909 0.00000 -0.07484108 0.000000
buguzelmi 0.7362599 2302.00000 -0.30617214 7.741534
DogrulariYaziyo 0.8489903 0.00000 -0.16370754 0.000000
你可以從這裏下載樣本數據: https://drive.google.com/open?id=0B1HBIov_NABWWXRobmZwV0Z2Tmc
我使用這個腳本來繪製;
p<-ggplot(data=test.data, aes(x=f.log, y=d.log)) +
stat_binhex(aes(x= f.log, y=d.log,alpha=..count..),fill="#000000")+
guides(fill=FALSE,colour=FALSE) +
geom_hline(yintercept = 0, size = 0.5,color="red",linetype = 2) +
geom_vline(xintercept = 0, size = 0.5,color="red",linetype = 2) +
theme_bw()
正如您所看到的,它會爲左上角的一個點創建一個六邊形,並且它不是數據的正確表示。
我的問題是,我可以在此代碼中執行scale_x_log10()函數內部的inf清理;
p<-ggplot(data=test.data, aes(x=friend_ratio, y=degree_ratio)) +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)))+
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)))+
geom_hex(aes(x= friend_ratio, y=degree_ratio))+
geom_hline(yintercept = 1, size = 0.5,color="red",linetype = 2)+
geom_vline(xintercept = 1, size = 0.5,color="red",linetype = 2)+
theme_bw()
我很困惑。我不明白你對第一個情節不喜歡什麼。它是頂部和底部的點嗎?將無限值設置爲0似乎是一個非常奇怪的選擇。你可以只是你的數據的子集?這可以在ggplot中輕鬆完成:'ggplot(data = subset(test.data,is.finite(d.log)&is.finite(f.log)),...' – Gregor
如果您想要最小的垃圾箱爲了完全透明,你可以添加'scale_alpha_continuous(range = c(0,1))'(默認最小值爲0.1),也可以對該變量進行對數轉換:scale_alpha_continuous(range = c(0,1 ),trans =「log」)' – Gregor
對不起,不好的解釋。我需要聚合點清楚地看到數據,是的,他們是頂部和底部的點,所以這是使用日誌規模的另一個原因。但它減少了所有數據中的幾乎75%,所以它沒有給出有關數據的任何想法。 – eabanoz