gpt4 book ai didi

r - 向 parcoord 添加刻度(平行坐标图)

转载 作者:行者123 更新时间:2023-12-01 04:27:04 26 4
gpt4 key购买 nike


MASS 包中的 parcoord 函数看起来很不错,但是我如何向
四个y轴?

代码在这里:

 ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3])
parcoord(log(ir)[, c(3, 4, 2, 1)], col = 1 + (0:149)%/%50)

enter image description here

最佳答案

您是否尝试设置 var.label=Tparcoord功能?这还不够吗?

否则,我没有看到任何使用默认功能更改轴的简单方法。但事实证明,该函数非常短,我们可以轻松地从它那里窃取想法并制作我们自己的版本。这是修改它的一种方法

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()
}

你可以运行它
ir <- log(rbind(iris3[,,1], iris3[,,2], iris3[,,3]))[,c(3,4,2,1)]
parcoordlabel(ir, col = 1 + (0:149)%/%50)

现在我承认它有点丑。但希望你能很好地理解这些片段来定制你喜欢的方式

sample plot

关于r - 向 parcoord 添加刻度(平行坐标图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23553210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com