How to fill colors correctly using geom_polygon in ggtern?

后端 未结 2 1065
眼角桃花
眼角桃花 2021-01-13 17:19

Here is the code which I am using to create boundaries in my ternary diagram:

library(ggtern)
DATA <- data.frame(x = c(0,0,0.04),
               y = c(1,0         


        
相关标签:
2条回答
  • 2021-01-13 17:59

    Try this:

    g <- data.frame(y=c(1,0,0),
                    x=c(0,1,.4),
                    z=c(0,0,.6),         Series="Green")
    
    p <- data.frame(y=c(1,0.475,0.6),
                    x=c(0,0.210,0),
                    z=c(0,0.315,.4),         Series="Red")
    
    q <- data.frame(y=c(0.575,0.475,0.0,0.0),
                    x=c(0.040,0.210,0.4,0.1),
                    z=c(0.385,0.315,0.6,0.9),         Series="Yellow")
    
    f <- data.frame(y=c(0.6,0.575,0.0,0.0),
                    x=c(0.0,0.040,0.1,0.0),
                    z=c(0.4,0.385,0.9,1.0),         Series="Blue")
    
    DATA = rbind(g, p, q, f)
    ggtern(data=DATA,aes(x,y,z)) + 
      geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
      scale_fill_manual(values=as.character(unique(DATA$Series))) +
      theme(legend.position=c(0,1),legend.justification=c(0,1)) + 
      labs(fill="Region",title="Sample Filled Regions")
    

    0 讨论(0)
  • 2021-01-13 18:17

    Have you tried geom_polygon(aes(fill=col), alpha=0.5) ?

    0 讨论(0)
提交回复
热议问题