Ellipse chart in R - extend axis

#1
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")
points(rbind(exy$loc), col = "blue", cex = 2, pch = 13)
 

Win

New Member
#3
You just need to adjust "xlim" and "ylim" like this:
Code:
plot(xy,xlab="Appointment", ylab="Sales", main = "Performance Report", type='n',xlim=c(-3,3),ylim=c(4,15))
If you want to master graphics in R, I would recommend the "R Fundamentals & Graphics" ebook. That's how I learned to hone my graphical skills in R.
 

trinker

ggplot2orBust
#4
Yes it does (ps include package calls in your code):

Code:
library(cluster)
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', ylim=c(3, 20))
# type = 'n' for no plots
# type = 'p' for points

lines(predict(exy), col="blue")
points(rbind(exy$loc), col = "blue", cex = 2, pch = 13)
 
#5
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

Ambassador to the humans
#6
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)