# Helper, to compute a circle
circle <- function(center=c(0,0), radius=1, segments=60) {
angles <- (0:segments)*2*pi/segments
circle <- radius * cbind( cos(angles), sin(angles))
t( c(center) + t( circle ))
}
# Create a circular ellipse
circ <- circle(radius=1.5)
plot(-2:2, -2:2,
type="n", asp=1,
main="Compass Directions on Circle\n(Cardinal + Diagonal)")
lines(circ, col="gray", lwd=2)
points(0, 0, pch="+", cex=2)
# Cardinal directions
cardinal <- c("N", "E", "S", "W")
for (pos in cardinal) {
label.ellipse(circ, label=pos, label.pos=pos, col="red", cex=1.2, font=2)
}
# Diagonal directions (recently added)
diagonal <- c("NE", "SE", "SW", "NW")
for (pos in diagonal) {
label.ellipse(circ, label=pos, label.pos=pos, col="blue", cex=1.2, font=2)
}
# Center, & illustrate return
xy <- label.ellipse(circ, label="C", label.pos="C", col="darkgreen", cex=1.2, font=2)
xy
# Add reference lines to show the angles
abline(h=0, v=0, col="lightgray", lty=2)
abline(a=0, b=1, col="lightgray", lty=2) # 45° line
abline(a=0, b=-1, col="lightgray", lty=2) # -45° line
legend("bottomleft",
legend=c("Cardinal (N,E,S,W)", "Diagonal (NE,SE,SW,NW)", "Center"),
col=c("red", "blue", "darkgreen"),
lwd=2, bty="n")
# Use in `heplot()`
data(dogfood, package = "heplots")
dogfood.mod <- lm(cbind(start, amount) ~ formula, data=dogfood)
# default: top or bottom, depending on sign of the ellipse
heplot(dogfood.mod,
fill = TRUE, fill.alpha = 0.1)
# change label.pos and cex
heplot(dogfood.mod,
fill = TRUE, fill.alpha = 0.1,
label.pos = c("NE", "SW"), cex = 1.4)
# Define diagonal compass positions and their corresponding angular fractions
# translate nmemonics to standard numerical text positions 1:4,
Run the code above in your browser using DataLab