1

I have the following data structure.

library(MASS)

mu1 <- c(2, -3)
mu2 <- c(2, 5)
rho <- 0.5
s1 <- 1
s2 <- 3
Sigma <- matrix(c(s1^2, rho * s1 * s2, rho * s1 * s2, s2^2), byrow = TRUE, nrow = 2)
n <- 50

X1 <- mvrnorm(n, mu = mu1, Sigma = Sigma)
X2 <- mvrnorm(n, mu = mu2, Sigma = Sigma)
y <- rep(c(0, 1), each = n)
X <- data.frame(rbind(X1, X2), class = y)

I wonder how to properly melt (produce long form) this data frame to produce the following scatter plot.

enter image description here

Andrej
  • 3,719
  • 11
  • 44
  • 73

0 Answers0