# Ellipse chart in R - extend axis

#### leejayd

##### New Member
Hi,

I'm using the code below to create an ellipses chart (using the Cluster package).

It works well except the ellipses hull can extend beyond the x&y axis.

Is there a way to extend the axis to ensure the ellipse hull doesn't fall outside the axis?

I've tried playing with xaxs but it seems the only settings in R are R (regular) and I (Internal).

Any ideas?

Code:
x <- rnorm(100)
xy <- unname(cbind(x, rnorm(100) + 2*x + 10))
exy <- ellipsoidhull(xy)

plot(xy,xlab="Appointment", ylab="Sales", main = "Performance Report", type='n')
# type = 'n' for no plots
# type = 'p' for points

lines(predict(exy), col="blue")

#### leejayd

##### New Member
Thanks Win & Trinker. You rock . I'll buy that book you mentioned.

I've been trying to produce this type of chart for yonks with Excel. An afternoon with R and it's sorted. This is my new fav visualization tool - never mind stats.

#### Dason

It's not too bad to dynamically figure out good ranges here - just use the range function.

Code:
library(cluster)
x <- rnorm(100)
xy <- unname(cbind(x, rnorm(100) + 2*x + 10))
exy <- ellipsoidhull(xy)

# dynamically figure out the ranges
pred <- predict(exy)
xlim <- range(pred[,1])
ylim <- range(pred[,2])

plot(xy,xlab="Appointment", ylab="Sales", main = "Performance Report", type='n',
xlim=xlim,
ylim=ylim)

lines(predict(exy), col="blue")
points(rbind(exy\$loc), col = "blue", cex = 2, pch = 13)