Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. library(ggtern)
  2. library(grid)
  3.  
  4. g <- data.frame(y=c(1,0,0),
  5. x=c(0,1,.4),
  6. z=c(0,0,.6), Series="Green")
  7.  
  8. p <- data.frame(y=c(1,0.475,0.6),
  9. x=c(0,0.210,0),
  10. z=c(0,0.315,.4), Series="Red")
  11.  
  12. q <- data.frame(y=c(0.575,0.475,0.0,0.0),
  13. x=c(0.040,0.210,0.4,0.1),
  14. z=c(0.385,0.315,0.6,0.9), Series="Yellow")
  15.  
  16. f <- data.frame(y=c(0.6,0.575,0.0,0.0),
  17. x=c(0.0,0.040,0.1,0.0),
  18. z=c(0.4,0.385,0.9,1.0), Series="Blue")
  19.  
  20. DATA = rbind(g, p, q, f)
  21. p <- ggtern(data=DATA,aes(x,y,z)) +
  22. geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
  23. scale_fill_manual(values=as.character(unique(DATA$Series))) +
  24. theme(legend.position=c(0,1),legend.justification=c(0,1)) +
  25. labs(fill="Region",title="Sample Filled Regions")+
  26. xlab("X=60")+ylab("Y=60")+zlab("Z=90")
  27.  
  28. gt <- ggplot_gtable(ggplot_build(p))
  29. grobPanel <- gt$grobs[[which(gt$layout$name == "panel")]]
  30. grobLabels <- grobPanel$children[[length(grobPanel$children)]]
  31. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[2]]$x <- unit(0.6,"npc")
  32. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[2]]$y <- unit(0.1,"npc")
  33. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[2]]$gp$fontsize <- 14
  34.  
  35. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[1]]$x <- unit(0.7,"npc")
  36. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[1]]$y <- unit(0.6,"npc")
  37. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[1]]$gp$fontsize <- 14
  38.  
  39. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[3]]$x <- unit(0.75,"npc")
  40. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[3]]$y <- unit(0.1,"npc")
  41. gt$grobs[[which(gt$layout$name == "panel")]]$children[[length(grobPanel$children)]]$children[[3]]$gp$fontsize <- 14
  42.  
  43. grid.draw(gt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement