[R] 3d graph question
Duncan Murdoch
murdoch at stats.uwo.ca
Thu May 17 22:44:31 CEST 2007
On 5/17/2007 3:42 PM, David Kaplan wrote:
> Hi, this is simple,
>
> I've generated a bivariate normal distribution with a known correlation.
> I want to plot the density function with p(y,x) on the vertical axis
> and x, and y on the horizontal axes. How is that done? Thanks in advance!
>
>
> library(MASS)
> mu <- c(0,1) # mean vector
> sigma <- matrix(c(1,.8,.8,1), ncol=2)
> tmp <- mvrnorm(1000, mu, sigma)
> cor(tmp)
> plot(tmp,ylab='achievement', xlab='ses') # plot data
You need to calculate the density for each element of an array whose
rows correspond to x values, and columns to y values. Then persp or
contour can plot it (or persp3d in the rgl package).
Duncan Murdoch
More information about the R-help
mailing list