【问题标题】:Is it possible to make a graph with pattern fills using TraMineR and R base graphs?是否可以使用 TraMineR 和 R 基础图制作带有图案填充的图?
【发布时间】:2015-02-24 15:40:32
【问题描述】:

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

是否可以使用 R 基础图形的图案填充功能或基础图形的扩展来向TraMineRgraphs 添加填充图案?

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

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"))

【问题讨论】:

  • TraMineR 使用基本图形而不是 ggplot2 或 grid(除了一些特殊功能)。大多数图形依赖于barplot。这是一个非常常见的问题,我对任何答案都很感兴趣。
  • 正如我的 Matthias 在 lists.r-forge.r-project.org/pipermail/traminer-users/2010-June/… 中解释的那样,您可以尝试使用 density 和 angle 参数,当 seqplot 调用此函数时将传递给 barplot,例如seqiplot(mvad.seq, cpal=brewer.pal(6, "Greys"), density=11:16, angle=1:6*5, border=NA) 。然而,解决方案几乎是令人信服的。我也会对具有专业外观的解决方案感兴趣。
  • 非常感谢您指出,TraMineR 使用基本图。使用来自 SO answer 的小技巧,密度/角度选项至少可以用于获得大约 6 个可微网格,并结合 5 种灰色阴影,这已经是一些东西了。

标签: r traminer


【解决方案1】:

在 cmets 之后,我想出了这个图形仍然可以改进的“解决方案”。不幸的是,我也无法覆盖图例,因此它们仍然需要一些工作。如果有人有想法,我会很高兴!?

## 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

【讨论】:

  • add=TRUE 选项对我不起作用,在做分组图时。第二个图只是第一个图的一个组子图上的灰色区域。也许 group 选项会创建自己的布局?我想知道如何应对。
  • 如果您使用seqplot 的group= 选项,那么,是的,它会自行调用layout。在这种情况下,您不能使用group=,您需要通过对每个组的数据集进行子集化来为每个组制作图表。看看这个SO comment。
  • 感谢您的澄清。不过我很好奇,如果此方法适用于单组图,并且 seqplot() 会干扰布局,从而阻止此方法用于多个组;那么是否可以在 inside seqplot(), @MatthiasStuder 中实现这个方法?可以肯定的是,在黑白印刷期刊上发表序列分析结果是一项非常常见的任务。应该有针对该目标的工具,而这种方法似乎是一种简单的出路。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
  • 2022-06-25
  • 2021-11-09
  • 2013-03-27
相关资源
最近更新 更多