Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. library(ggplot2)
  2. library(ggtern)
  3. library(reshape2)
  4. library(gridExtra)
  5.  
  6. # Some faux data
  7. dat <- replicate(3, runif(5))
  8. dat <- as.data.frame(dat/rowSums(dat))
  9. colnames(dat) <- LETTERS[seq_len(ncol(dat)) + 23]
  10. dat$var <- factor(LETTERS[seq_len(nrow(dat))])
  11.  
  12. # Make a ternary plot
  13. tern.plot <-
  14. ggplot(data = dat, aes(y=Y, x=X, z=Z, color = var, fill = var)) +
  15. coord_tern() +
  16. geom_point(size = 3)
  17.  
  18. # Make a stacked barplot
  19. dat.melt <- melt(dat, id.vars = "var", variable_name = "dim")
  20. stacked.plot <-
  21. ggplot(data = dat.melt, aes(x = var, y = value, fill = dim)) +
  22. geom_bar(stat = "identity")
  23.  
  24. # Arrange the two plots:
  25. grid.arrange(tern.plot, stacked.plot, ncol = 2)
  26. #Warning messages:
  27. #1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
  28. #2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
  29. # ...
  30. #9: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
  31.  
  32. print(tern.plot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement