How to adjust y axis using seqIplot in R?

I am trying to adjust the Y axis of a sequence index graph using the TraMineR R package, I figured out how to set a global limit for the y axis, which is useful if you want to compare the number of specific sequences between two or more groups as it aligns the scale. But I was not able to check the y axis (as in xtstep). Perhaps you can help me quickly using this code example:

 library(TraMineR) data(mvad) mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school", "training") mvad.labels <- c("Employment", "Further Education", "Higher Education", "Joblessness", "School", "Training") mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR") ## Define sequence objects mvad.seq <- seqdef(mvad[, 17:86], alphabet = mvad.alphabet, states = mvad.scodes, labels = mvad.labels, weights = mvad$weight, xtstep = 6) ## Plots seqIplot(mvad.seq, group=mvad$gcse5eq, withlegend=TRUE, border=NA, xtstep=3, sortv="from.start") ## Default plot seqIplot(mvad.seq, group=mvad$gcse5eq, withlegend=TRUE, border=NA, xtstep=3, sortv="from.start", ylim=c(0, 400)) ## Plot with custom ylim to compare the number of sequences between groups 

The default sequence index string looks so very difficult to compare two groups: Default sequence index plot

+2
source share
1 answer

When a ylim is specified in seqIplot , it is used for all groups. To make the height of the graph proportional to the weighted number of sequences in each group, the top ylim should be set as the value for the most frequent group.

 group <- mvad$gcse5eq (nseq <- xtabs(mvad$weight ~ group)) (nmax <- max(nseq)) seqIplot(mvad.seq, group=group, withlegend=TRUE, border=NA, xtstep=3, sortv="from.start", ylim=c(0, nmax) ) 

Tick ​​marks on the y axis are sequence indexes. You can suppress them by pointing yaxis = FALSE to seqIplot . To display your own shortcuts, you can then output something like this (see the axis function help for more details).

 axis(2, at = c(1, nseq[1])) 

but in this case you have to generate seqIplot separately for each group using withlegend=FALSE and organize the charts on your own in one chart using layout or par(mfrow=...) .

+2
source

Source: https://habr.com/ru/post/1501402/


All Articles