I'm plotting a bivariate circular normal distribution in R:
library(MASS)
library(mnormt)
set.seed(0)
# create bivariate normal distribution
x <- seq(-4, 4, 0.1)
y <- seq(-4, 4, 0.1)
mu <- c(0, 0)
sigma <- matrix(c(1, 0, 0, 1), nrow=2)
f <- function(x, y) dmnorm(cbind(x, y), mu, sigma)
z <- outer(x, y, f)
# create contour plot
contour(x,y,z)
The contours should be circular, but instead they are elliptical because the width of the plot > the height of the plot.
What I've tried:
- I consulted the for documentation the function but didn't notice any argument that could be set.
- I think ggplot2 accomplishes a fixed aspect ratio via the coord_fixed function - but again, I don't see anything similar for the
contour
function - I set
dev.new(width=5, height=5)
as recommended by this SO answer but it didn't change anything (maybe I'm implementing it incorrectly).
So, is there a simple way to enforce circular contours using the contour
function (I'm guessing there is since it feels like a pretty basic need), or should I just switch over to using ggplot2?