How to tweak the size of a bivariate distribution in R?

, ,

For illustrative purposes, I am trying to draw a small bivariate normal distribution. I would like it to be tight, centered at (3,4;1), and with a radius of 0.5 or less. Below see the code I am using (from this website); I have tried to tweak it in different ways, but the bivariate is always spread out.

N <- 200 # Number of random samples
# Parameters 
rho <- 0.5
mu1 <- 3.4; s1 <- 1
mu2 <- 1; s2 <- 1

# Parameters for bivariate normal distribution
mu <- c(mu1,mu2) # Mean 
sigma <- matrix(c(s1^2, s1*s2*rho, s1*s2*rho, s2^2),
                2) # Covariance matrix
X <- mvrnorm(N, mu = mu, Sigma = sigma)
z <- kde2d(X[,1], X[,2], n=50)
plot(X, xlab="X label", ylab="Y label",  xlim=c(2,6), ylim=c(-1,3.5),pch=19, cex=.4)
contour(z, drawlabels=FALSE, add=TRUE)

Created on 2021-01-05 by the reprex package (v0.3.0)

mu1 <- 3.4; s1 <- .25
mu2 <- 1; s2 <- .25


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.