color discrete groups of parallel coordinate plot in GGally package

To create a parallel coordinate plot I wanted to use ggparcoord() function in package GGally . The following codes show a reproducible example.

set.seed(3674)
k <- rep(1:3, each=30)
x <- k + rnorm(mean=10, sd=.2,n=90)
y <- -2*k + rnorm(mean=10, sd=.4,n=90)
z <- 3*k + rnorm(mean=10, sd=.6,n=90)

dat <- data.frame(group=factor(k),x,y,z)

library(GGally)
ggparcoord(dat,columns=1:4,groupColumn = 1)

在这里输入图像描述

Notice in the picture that the color for group was continuous even though I have the group variable as a factor. Is there any way I can display the plot with three discrete color instead?

I have looked at some other posts where they discuss various other ways of doing parallel coordinate plots in here. But I really wanted to do this in ggparcoord() function of package GGally . I appreciate your time in thinking about this problem.


Your code was almost correct. I spotted that columns=1:4 was not right in this case. You need to drop the column for groupColumn in columns

ggparcoord(dat,columns=2:4,groupColumn = 1)

在这里输入图像描述

链接地址: http://www.djcxy.com/p/30932.html

上一篇: 控制ggparcoord中的颜色(来自GGally包)

下一篇: GGally包中的平行坐标图的颜色离散组