将刻度添加到parcoord(平行坐标图) [英] add ticks to parcoord (parallel coordinates plot)

查看:131
本文介绍了将刻度添加到parcoord(平行坐标图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MASS软件包中的
parcoord函数看起来还不错,但是如何在四个y轴上向
添加刻度线呢?

The parcoord function from the MASS package looks quite ok, but how can I add ticks to the four y-axis?

代码在这里:

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

推荐答案

您是否尝试在其中设置 var.label = T parcoord 函数?

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

,您可以使用

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

这篇关于将刻度添加到parcoord(平行坐标图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆