0

頻度が列内で計算される、頻度の 2D ヒストグラムを生成するのに役立ちます。私の主な問題: カウントから列ベースの頻度への変換。

これが私の開始コードです:

# expected packages
library(ggplot2)
library(plyr)

# generate example data corresponding to expected data input
x_data = sample(101:200,10000, replace = TRUE)
y_data = sample(1:100,10000, replace = TRUE)
my_set = data.frame(x_data,y_data)

# define x and y interval cut points
x_seq = seq(100,200,10)
y_seq = seq(0,100,10)

# label samples as belonging within x and y intervals
my_set$x_interval = cut(my_set$x_data,x_seq)
my_set$y_interval = cut(my_set$y_data,y_seq)

# determine count for each x,y block
xy_df = ddply(my_set, c("x_interval","y_interval"),"nrow") # still need to convert for use with dplyr

# convert from count to frequency based on formula: freq = count/sum(count in given x interval)
################ TRYING TO FIGURE OUT #################

# plot results
fig_count <- ggplot(xy_df, aes(x = x_interval, y = y_interval)) + geom_tile(aes(fill = nrow)) # count
fig_freq <- ggplot(xy_df, aes(x = x_interval, y = y_interval)) + geom_tile(aes(fill = freq)) # frequency

列内の頻度を計算する方法について助けていただければ幸いです。

ありがとう!ジャック

編集: ソリューションには次の手順が必要になると思います。1) x 間隔係数ごとに全体のカウントを計算して保存します。2) 個々のビン数を対応する x 間隔係数カウントで割り、頻度を取得します。

ただし、これを実行する方法がわかりません。.

4

1 に答える 1