3

ggplot2 パッケージのstat_ecdf()機能部分が気に入っています。これは、データ シリーズを調べるのに非常に役立ちます。ただし、これは視覚的なものにすぎません。関連するテーブルを取得する方法はありますか?

次の再現可能な例を見てください

p <- ggplot(iris, aes_string(x = "Sepal.Length")) + stat_ecdf() # building of the cumulated chart 
p
attributes(p) # chart attributes
p$data # data is iris dataset, not the serie used for displaying the chart

ここに画像の説明を入力

4

2 に答える 2

2

データを再作成できます。

#Recreate ecdf data
dat_ecdf <- 
  data.frame(x=unique(iris$Sepal.Length),
             y=ecdf(iris$Sepal.Length)(unique(iris$Sepal.Length))*length(iris$Sepal.Length))
#rescale y to 0,1 range
dat_ecdf$y <- 
  scale(dat_ecdf$y,center=min(dat_ecdf$y),scale=diff(range(dat_ecdf$y)))

以下の 2 つのプロットは同じように見えるはずです。

#plot using new data
ggplot(dat_ecdf,aes(x,y)) +
  geom_step() +
  xlim(4,8)

#plot with built-in stat_ecdf
ggplot(iris, aes_string(x = "Sepal.Length")) +
  stat_ecdf() +
  xlim(4,8)
于 2015-05-22T12:59:33.297 に答える