如何在R中使用seqIplot配置y轴? [英] How to configure y-axis using seqIplot in R?

查看:75
本文介绍了如何在R中使用seqIplot配置y轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R-package TraMineR配置序列索引图的y轴,我想出了如何为y轴设置全局限制,如果您想比较两个或两个以上组之间的某些序列使比例相等.但是我没有设置y轴刻度(如xtstep).也许您可以使用以下示例代码快速帮助我:

I am trying to configure the y-axis of a sequence index plot using the R-package TraMineR, I figured out how to set a global limit for the y-axis which is helpful if you want compare the number of certain sequences between two or more groups as it equalizes the scale. But I did not manage to set the y-axis ticks (as in xtstep). Maybe you can quickly help me out using this example code:

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 plot looks like this and makes it very difficult to compare the two groups:

推荐答案

seqIplot中给出ylim时,它将用于所有组.为了使绘图高度与各组中加权的序列数成正比,应将上限ylim设置为最频繁组的值.

When a ylim is given in seqIplot, it is used for all groups. To make the plot heights proportional to the weighed number of sequences in each group, the upper ylim should be set as the value for to 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) )

y轴上的刻度标签是序列索引.您可以通过将yaxis = FALSE赋予seqIplot来抑制它们.要显示自己的标签,您可以发出类似的标签(有关详细信息,请参见axis功能的帮助)

The tick labels on the y axis are sequence indexes. You can suppress them with by giving yaxis = FALSE to seqIplot. To display your own labels you can then issue something like (see the help of the axisfunction for details)

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

,但是在这种情况下,应该使用withlegend=FALSE为每个组分别生成seqIplot,并使用layoutpar(mfrow=...)将自己的图组织在单个图形中.

but in that case you should generate the seqIplot separately for each group with withlegend=FALSE and organize the plots yourself in a single graphic with layout or par(mfrow=...).

这篇关于如何在R中使用seqIplot配置y轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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