r - Creating bivariate normal distribution ellipse on plot that has log-transformed x and y axis -
although have found many answers on how draw bivariate normal distribution ellipse on existing plot, have question regarding plotting ellipse onto existing plot x- , y-axis log-transformed.
as example have following data add ellipse
library(mixtools) library(truncnorm) x<-rtruncnorm(n=100, a=0, b=20) y=1+.3*x+.3*rnorm(100) data<-cbind(x,y) mu <-c(mean(x), mean(y)) sigma <- var(data) plot(data) ellipse(mu, sigma, alpha=0.1, npoints = 200, newplot = false)
however, actual data requires use log transformed x- , y-axis, so
plot(data,log="xy")
when plotting "ellipse" function, no longer ellipse
ellipse(mu, sigma, alpha=0.1, npoints = 200, newplot = false)
adding "log" ellipse function specifications no option
ellipse(mu, sigma, alpha=0.1, npoints = 200, newplot = false,log="xy")
warning message: in plot.xy(xy.coords(x, y), type = type, ...) : "log" not graphical parameter.
can me out one?
thank you!
package car
can handle ellipses in log-transformed space. here taste of can do. 1 line without log argument while full ellipse log argument.
library(car) plot.default(data, log = "xy") car::ellipse(center = log(mu), shape = sigma, radius = 3, center.pch = null)
Comments
Post a Comment