是否可以使用TraMineR和R基本图制作带有图案填充的图? [英] Is it possible to make a graph with pattern fills using TraMineR and R base graphs?

查看:65
本文介绍了是否可以使用TraMineR和R基本图制作带有图案填充的图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处输入图片描述常见问题 1 2 在发布序列分析或一般情况下具有许多分类状态的图的一个特点是它们不容易转移到黑白纸质出版物上.有一些工具,例如 Colorbrewer ,可以帮助您对灰度颜色做出明智的决定.但是,如果调色板超过5个或更多的灰色阴影,结果将不能令人满意.因此,在这种情况下,将填充图案添加到某些图形区域确实很有帮助(尽管著名的Edward Tufte不建议这样做).

enter image description hereA common problem1 2 in the publication of a sequence analysis or generally of graphs with many categorical states is that they are not easily transferable to b/w paper publications. There are some tools, like Colorbrewer, which can help to make a well informed decision on grey scale colors. Nonetheless, the results are unsatisfactory if the color palette exceeds 5 or more shades of greys. Thus, it would be really helpful to add pattern fills to certain graph areas in these cases (although this is not recommended by the famous Edward Tufte).

是否可以使用R基本图形的图形填充功能或基本图形的扩展功能将填充图形添加到TraMineR图形?

Would it be possible to use the pattern fill abilities of R base graphics or an extension of the base graphics to add fill patterns to TraMineRgraphs?

这是序列索引图的一个小例子:

Here is small example of a sequence index plot:

library(TraMineR)

library(RColorBrewer)

## Load example dataset with 8 sequence states 
data(biofam)

## Define sequence objects 
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
                "Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)

## Example plot in colors
seqiplot(biofam.seq, cex.legend=.7)

## Example plot in greys for b/w publication
seqiplot(biofam.seq, cex.legend=.7, cpal=brewer.pal(8, "Greys"))

推荐答案

在评论之后,我想出了该解决方案",其图形仍可改进.不幸的是,我也无法覆盖这些图例,因此它们仍然需要一些工作.如果有人有主意我会很高兴!?

Following the comments, I came up with this "solution" whose graphics are still improvable. Unfortunately, I was not able to overwrite the legends as well, so that they still need some work. I would be happy if someone had an idea!?

## Define smaller black/grey palette, delete almost white tones
greys <- c("black", "black", "black", "black", brewer.pal(5, "Greys")[2:5])

## Example plot using density and overwriting angle options
par(mar=c(1,2,1,1))
layout(matrix(c(1,2), 2, 1, byrow = TRUE), heights=c(2,1))
seqiplot(biofam.seq, withlegend=FALSE,
         cpal=greys,
         density=c(20, 20, 20, 20, -1, -1, -1, -1), 
         angle=c(45, 90, 45, 0, 0, 0, 0, 0))
seqiplot(biofam.seq, withlegend=FALSE,
         cpal=greys,
         density=c(20, 20, 20, 20, -1, -1, -1, -1), 
         angle=c(45, 90, 135, 0, 0, 0, 0, 0),
         add=TRUE)
         # Different angle for third state creates grid instead of patterns
seqlegend(biofam.seq, pos="center", ncol=3, fontsize=.7,
          cpal=greys,
          density=c(20, 20, 20, 20, -1, -1, -1, -1), 
          angle=c(45, 90, 45, 0, 0, 0, 0, 0))
seqlegend(biofam.seq, pos="center", ncol=3, fontsize=.7,
          cpal=greys,
          density=c(20, 20, 20, 20, -1, -1, -1, -1), 
          angle=c(45, 90, 135, 0, 0, 0, 0, 0))
          # Draws an additional legend instead of overwriting the first

这篇关于是否可以使用TraMineR和R基本图制作带有图案填充的图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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