R: gap when printing polygons with holes in ggplot2

I am trying to capture these body maps and cannot correctly show my face. The โ€œheadsโ€ consist of two polygons: one is the face (solid oval), and the other is the rest of the head (hole in the shape of a hole, hole in the center). They should be colored depending on the value of the column "grade". I have tried so many variations that fit group = group , and fill = scale .

real data comparison

  ggplot(data=Patients, aes(y=lat, 
                            x=long, 
                            fill=factor(score), 
                            group=group))+
    geom_polygon(color="black")+
    facet_wrap(~Patient, 
               ncol = 5)+
    scale_fill_manual(values=scoreColor)+
    coord_fixed()

Any help would be greatly appreciated.

I included my attempt at a reproducible example below.

library(ggplot2)
fortifyResults <-read.table(header=T, stringsAsFactors = F, text="
                  long  lat order   hole    piece   group   id  score
                  1 1   1   FALSE   1   Outer.1 Outer   20
                  1 4   2   FALSE   1   Outer.1 Outer   20
                  4 4   3   FALSE   1   Outer.1 Outer   20
                  4 1   4   FALSE   1   Outer.1 Outer   20
                  1 1   5   FALSE   1   Outer.1 Outer   20
                  2 2   6   TRUE    2   Outer.2 Outer   20
                  3 2   7   TRUE    2   Outer.2 Outer   20
                  3 3   8   TRUE    2   Outer.2 Outer   20
                  2 3   9   TRUE    2   Outer.2 Outer   20
                  2 2   10  TRUE    2   Outer.2 Outer   20
                  2 2   11  FALSE   1   Inner.1 Inner   10
                  2 3   12  FALSE   1   Inner.1 Inner   10
                  3 3   13  FALSE   1   Inner.1 Inner   10
                  3 2   14  FALSE   1   Inner.1 Inner   10
                  2 2   15  FALSE   1   Inner.1 Inner   10
                  ")

In this version of the code, both parts are not displayed (although they are in the legend)

ggplot(data=fortifyResults, aes(y=lat, x=long, group=group))+
  geom_polygon(aes(fill=factor(score)),color="black")

And it causes breaks

ggplot(data=fortifyResults, aes(y=lat, x=long), group=group)+
  geom_polygon(aes(fill=factor(score)),color="black")

example comparison

I read that the direction of the points matters. So the direction is called.

ggplot(data= fortifyResults, aes(y=lat, x=long, group=group))+   
  geom_polygon(fill="yellow", color="black")+
  geom_text(aes(label=order),hjust=0, vjust=-0.3)+
  facet_wrap(~id)

enter image description here

, "" ( == ). , , . , . , , , .

+4

Source: https://habr.com/ru/post/1618674/


All Articles