Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何避免geom_六边形变平_R_Ggplot2 - Fatal编程技术网

R 如何避免geom_六边形变平

R 如何避免geom_六边形变平,r,ggplot2,R,Ggplot2,我想用ggplot2以不同的颜色绘制一些六边形。 当我尝试下面的代码时,我得到了挤压六边形 library(ggplot2) coords <- data.frame(x=c(1.11803398874989,0.559016994374948,-0.559016994374947,-1.11803398874989,-0.559016994374948,0.559016994374947,2.23606797749979,1.1180339887499,-1.1180339887498

我想用
ggplot2
以不同的颜色绘制一些六边形。 当我尝试下面的代码时,我得到了挤压六边形

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.73839349132101e-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 ()
当我不舍入这些值时,我得到一个空的绘图。 有什么问题吗


谢谢

我只想画19个不重叠的六边形。为此,我可以将其绘制如下:

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)) 
coords
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))