Reputation: 23104
The parcoord function from the MASS package looks quite ok, but how can I add ticks to the four y-axis?
Code is here:
ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3])
parcoord(log(ir)[, c(3, 4, 2, 1)], col = 1 + (0:149)%/%50)
Upvotes: 4
Views: 1990
Reputation: 206197
Did you try setting var.label=T
in the parcoord
function? Is that insufficient?
Otherwise i didn't see any easy way to change the axis with the default function. But it turns out that function is pretty short and we can easily steal ideas form it and make our own version that can. Here's one way to modify it
parcoordlabel<-function (x, col = 1, lty = 1, lblcol="blue",...)
{
df <- as.data.frame(x)
pr <- lapply(df, pretty)
rx <- lapply(pr, range, na.rm = TRUE)
x <- mapply(function(x,r) {
(x-r[1])/(r[2]-r[1])
},
df, rx)
matplot(1L:ncol(x), t(x), type = "l", col = col, lty = lty,
xlab = "", ylab = "", axes = FALSE, ...)
axis(1, at = 1L:ncol(x), labels = colnames(x))
for (i in 1L:ncol(x)) {
lines(c(i, i), c(0, 1), col = "grey70")
text(c(i, i), seq(0,1,length.out=length(pr[[i]])), labels = pr[[i]],
xpd = NA, col=lblcol)
}
invisible()
}
and you can run it with
ir <- log(rbind(iris3[,,1], iris3[,,2], iris3[,,3]))[,c(3,4,2,1)]
parcoordlabel(ir, col = 1 + (0:149)%/%50)
Now i will admit it's a bit ugly. But hopefully you can understand the pieces well enough to customize how you like
Upvotes: 3