2017-11-01 12 views
0

私は行ごとにx座標とy座標とのデータの束を有し、TRUE/FALSEセイ:確率ヒートマップをggplot2でプロットするにはどうすればよいですか?

library(tidyverse) 
set.seed(666) #666 for the devil 
x <- rnorm(1000, 50, 10) 
y <- sample(1:100, 1000, replace = T) 
result <- sample(c(T, F), 1000, prob = c(1, 9),replace = T) 
data <- tibble(x, y, result) 

ここで、Iはそのデータに基づいてTRUEある領域の尤度を示すグラフを作成したいです。私はグループの小さな正方形にデータ(または何でも)とTRUE割合を計算し、そのプロットが、自動的に私のためにそれを行いますggplot2で何かがある場合、私は何だろう可能性があります。

+0

オフトピックですか?与えられた特定の理由は正確ではありません。私は "なぜこのコードは動作していないのですか?"と尋ねなかった。私は「私はXのやり方を知らない、どうやってXをやるの?」と尋ねた。それは私の理解とは違って、このウェブサイトの全体のポイントではありません。 – Mart

答えて

1
ggplot(data, aes(x = x, y = y, z = as.numeric(result))) + 
    stat_summary_2d(bins = 20, color = "grey", fun = mean) +   
    theme_classic() 

enter image description here

0
ない完全 ggplot2

が、以下は、私はあなたが

library(tidyverse) 
library(broom) 
set.seed(666) #666 for the devil 

data.frame(x = rnorm(1000, 50, 10), 
      y = sample(1:100, 1000, replace = T), 
      result = sample(c(T, F), 1000, prob = c(1, 9), replace = T)) %>% 
    do(augment(glm(result ~ x * y, data = ., family = "binomial"), type.predict = "response")) %>% 
    ggplot(aes(x, y, color = .fitted)) + 
    geom_point() 

またはその代わりgeom_pointgeom_hexを求めていると思うものを生産するには、これがあると思われる

0

面白そうです他の解決策:

library(tidyverse) 

#Preparing data 
set.seed(666) #666 for the devil 
data <- tibble(x = rnorm(1000, 50, 10), 
       y = sample(1:100, 1000, replace = T), 
       result = sample(c(T, F), 1000, 
           prob = c(1, 9), replace = T)) %>% 
filter(result == TRUE) 

#Plotting with ggplot 
ggplot(data, aes(x, y)) + 
geom_bin2d() 

Result geom_bin2d

関連する問題