问题
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).
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 TraMineR
graphs?
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"))
回答1:
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
来源:https://stackoverflow.com/questions/28700002/is-it-possible-to-make-a-graph-with-pattern-fills-using-traminer-and-r-base-grap