Guest User

Untitled

a guest
Jan 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. library(ggplot2)
  2.  
  3. x.centers <- c(0, .14, -.164)
  4. x.ses <- c(0.5, 0.2, 0.12)
  5. y.centers <- c(0.01,.13, -.13)
  6. y.ses <- c(0.05, 0.13, 0.24)
  7.  
  8. NN <- 1000#00
  9. Sample1 <- cbind(rnorm(NN, x.centers[1], x.ses[1]), rnorm(NN, y.centers[1], y.ses[1]))
  10. Sample2 <- cbind(rnorm(NN, x.centers[2], x.ses[2]), rnorm(NN, y.centers[2], y.ses[2]))
  11. Sample3 <- cbind(rnorm(NN, x.centers[3], x.ses[3]), rnorm(NN, y.centers[3], y.ses[3]))
  12.  
  13. PlotFrame <- data.frame(cbind(rep(c("G1", "G2", "G3"), each = NN), rbind(Sample1, Sample2, Sample3)))
  14. colnames(PlotFrame) <- c("LABELS", "X", "Y")
  15. PlotFrame[, 2:3] <- apply(PlotFrame[, 2:3], 2, as.numeric)
  16.  
  17. Plot1 <- ggplot(data = PlotFrame, aes(x = X, y = Y, colour = LABELS))
  18. Plot1 <- Plot1 + geom_density2d()
  19. print(Plot1)
  20.  
  21. Plot2 <- ggplot(data = PlotFrame, aes(x = X, y = Y, group = LABELS))
  22. Plot2 <- Plot2 + stat_density2d(aes(colour = ..level..), fill = "transparent", geom="polygon")
  23. print(Plot2)
  24.  
  25. Plot3 <- ggplot(data = PlotFrame, aes(x = X, y = Y, group = LABELS))
  26. Plot3 <- Plot3 + stat_density2d(aes(fill = LABELS, colour = LABELS, alpha = ..level..), geom="polygon")
  27. print(Plot3)
Add Comment
Please, Sign In to add comment