Re: [R] 3d graph question

From: Duncan Murdoch <>
Date: Thu, 17 May 2007 16:44:31 -0400

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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 17 May 2007 - 20:50:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 May 2007 - 21:31:44 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.