You can't use directly facet_wrap()
with function ggparcoord()
because this function use as data only those columns which are specified in call to this function. It can be seen by looking on data element of p2
. There is no column named set
.
p2 <- ggparcoord(x, columns=1:3, groupColumn=4)
head(p2$data)
type .ID anyMissing variable value
1 x 1 FALSE var1 0.95473093
2 y 2 FALSE var1 -0.05566205
3 x 3 FALSE var1 2.57548872
4 y 4 FALSE var1 0.14508261
5 x 5 FALSE var1 -0.92022584
6 y 6 FALSE var1 -0.05594902
To get the same type of plot with faceting, first, you need to add new column (contains just numbers corresponding to number of cases) to existing data frame and then reshape this data frame.
x$ID<-1:40
df.x<-melt(x,id.vars=c("set","ID","type"))
Then use function ggplot()
and geom_line()
to plot data.
ggplot(df.x,aes(x=variable,y=value,colour=type,group=ID))+
geom_line()+facet_wrap(~set)