2017-06-04 16 views
0

ggplot2で六角形を色分けしてプロットしたいと思います。私は押しつぶされた六角形geom_hexの六角形が平らにならないようにする方法

library(ggplot2) 
coords <- 
data.frame(x=c(1.11803398874989,0.559016994374948,-0.559016994374947,-1.11803398874989,-0.559016994374948,0.559016994374947,2.23606797749979,1.1180339887499,-1.11803398874989,-2.23606797749979,-1.1180339887499,1.11803398874989,1.73205080756888,1.22464679914735e-16), 
      y=c(0,0.968245836551854,0.968245836551854,1.36919674566051e-16,-0.968245836551854,-0.968245836551855,0,1.93649167310371,1.93649167310371,2.1e-16,-1.93649167310371,-1.93649167310371,1,2), 
      kind=c(rep("blue",12),"red","blue")) 

ggplot (data = coords, aes (x = round(x,digits =13), y = round(y,digits=13), fill = kind , group = 1)) + 
    geom_hex (colour = "red", stat = StatIdentity) + 
    scale_x_continuous(expand = 0 : 1) + 
    scale_y_continuous(expand = c (0, 2)) + 
    coord_equal() 

を得るの下に、私はコードとしてそれをしようとすると、私は唯一の最初の12個の六角形をプロットしてみたときに、私がいないとき は、しかし、私はまた何の問題

# fine result 
ggplot (data = coords[1:12,], aes (x = round(x,digits =13), y = round(y,digits=13), fill = kind , group = 1)) + 
    geom_hex (colour = "red", stat = StatIdentity) + 
    scale_x_continuous(expand = 0 : 1) + 
    scale_y_continuous(expand = c (0, 2)) + 
    coord_equal() 

を持っていません値を丸めて、私は空のプロットを得る。 何が問題なのでしょうか?私は重複しない19個の六角形を描きたかった

おかげ

答えて

0

。その目的のために私は以下のように描くことができました:

coords <- 
    data.frame(
    x = c(2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7), 
    y = c(2, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 5, 5), 
    kind=c(rep("blue",12),"red","blue","red","blue",rep("blue",3)) 
) 

ggplot (data = coords, aes (x = x, y = y, fill = kind , group = 1)) + 
    geom_hex (colour = "red", stat = StatIdentity) + 
    scale_x_continuous(expand = c(0:1)) + 
    scale_y_continuous(expand = c(0,2)) 

フロートを避ける方が良いようです。

関連する問題