1

我想使用点在 ggplot 中绘制我的数据。它创建了这个图: 在此处输入图像描述

如您所见,这并不好,因此我决定使用对数刻度来获得更好的结果,并且我的数据有 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() 
4

1 回答 1

2

将我的评论变成答案,您可以使用对数刻度来填充透明度

scale_alpha_continuous(range = c(0, 1), trans = "log")

指定范围从 0 开始将使最小的 bin 完全透明,这意味着您不会看到少量点的六边形。

于 2015-10-10T00:07:41.737 回答