如何在一组图中对stripplot上的点进行着色

时间:2014-02-15 11:15:05

标签: r plot

我使用的格子包含以下代码:

stripplot(locs~factor(rep(1,length(locs)))|dataset,
                  col=locs.col,
                  pch=19,cex=0.7,
                  jitter.data=T,factor=rep(rnorm(length(locs))),
                  amount=abs(rep(rnorm(length(locs))))*0.05 )

然而,与我的预期相比,这似乎是错误的。如果我单独根据数据集中的因子进行绘制,则绘制的第二个和第三个绘图分别与我在组合点阵图中得到的颜色不同。

例如第二个单独的情节:

stripplot(locs[101:200]~factor(rep(1,length(locs[101:200])))|dataset[101:200],
                      col=locs.col[101:200],
                      pch=19,cex=0.7,
                      jitter.data=T,factor=rep(rnorm(length(locs[101:200]))),
                      amount=abs(rep(rnorm(length(locs[101:200]))))*0.05 )

与我在第二个小组的情节中得到的相同。

我尝试改变数据集值的顺序,但这不起作用。

我把数据放在下面。

locs=c(44L, 71L, 93L, 69L, 67L, 58L, 107L, 57L, 66L, 54L, 73L, 59L, 
43L, 65L, 64L, 60L, 45L, 83L, 79L, 85L, 83L, 73L, 66L, 64L, 43L, 
84L, 39L, 43L, 130L, 80L, 57L, 91L, 62L, 40L, 60L, 65L, 97L, 
47L, 83L, 44L, 120L, 95L, 44L, 51L, 68L, 44L, 74L, 72L, 55L, 
68L, 67L, 63L, 52L, 54L, 86L, 67L, 67L, 47L, 54L, 53L, 76L, 38L, 
67L, 66L, 71L, 52L, 69L, 46L, 71L, 64L, 43L, 56L, 69L, 69L, 94L, 
45L, 41L, 67L, 43L, 73L, 81L, 51L, 43L, 94L, 75L, 45L, 52L, 42L, 
93L, 44L, 44L, 80L, 45L, 68L, 41L, 101L, 66L, 64L, 45L, 52L, 
51L, 44L, 48L, 80L, 50L, 55L, 48L, 80L, 88L, 47L, 90L, 72L, 43L, 
54L, 96L, 54L, 45L, 76L, 59L, 45L, 75L, 53L, 46L, 95L, 43L, 112L, 
44L, 47L, 46L, 44L, 105L, 91L, 72L, 106L, 89L, 123L, 49L, 46L, 
70L, 81L, 41L, 100L, 85L, 48L, 54L, 85L, 46L, 140L, 94L, 47L, 
80L, 106L, 77L, 59L, 46L, 90L, 49L, 91L, 41L, 50L, 37L, 46L, 
47L, 81L, 33L, 60L, 49L, 49L, 47L, 47L, 59L, 48L, 67L, 45L, 77L, 
102L, 96L, 146L, 86L, 44L, 124L, 113L, 54L, 93L, 53L, 48L, 114L, 
72L, 47L, 46L, 56L, 86L, 89L, 49L, 47L, 45L, 46L, 55L, 101L, 
76L, 91L, 46L, 128L, 117L, 123L, 112L, 68L, 68L, 40L, 53L, 61L, 
42L, 43L, 66L, 34L, 50L, 43L, 88L, 111L, 93L, 39L, 120L, 33L, 
52L, 86L, 90L, 38L, 78L, 94L, 89L, 129L, 49L, 107L, 79L, 88L, 
67L, 42L, 34L, 119L, 43L, 65L, 90L, 45L, 95L, 94L, 74L, 112L, 
47L)

dataset=structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("T1", 
"H2", "V6"), class = "factor")  

locs.col=c("darkblue", "yellow", "red", "yellow", "yellow", "yellow", 
"red", "yellow", "yellow", "yellow", "yellow", "yellow", 
"darkblue", "yellow", "yellow", "yellow", "darkblue", 
"yellow", "yellow", "yellow", "yellow", "red", "yellow", 
"yellow", "darkblue", "yellow", "darkblue", "darkblue", 
"red", "red", "yellow", "yellow", "yellow", "darkblue", 
"yellow", "yellow", "red", "yellow", "red", "darkblue", 
"red", "red", "darkblue", "darkblue", "yellow", "darkblue", 
"red", "yellow", "yellow", "yellow", "yellow", "yellow", 
"yellow", "yellow", "red", "yellow", "yellow", "yellow", 
"yellow", "yellow", "yellow", "darkblue", "yellow", 
"yellow", "yellow", "yellow", "yellow", "yellow", 
"yellow", "yellow", "darkblue", "yellow", "yellow", 
"yellow", "yellow", "darkblue", "darkblue", "yellow", 
"darkblue", "yellow", "yellow", "darkblue", "darkblue", 
"red", "yellow", "darkblue", "yellow", "darkblue", "yellow", 
"darkblue", "darkblue", "yellow", "darkblue", "red", "darkblue", 
"red", "yellow", "red", "darkblue", "darkblue", "darkblue", 
"darkblue", "darkblue", "yellow", "darkblue", "darkblue", 
"darkblue", "yellow", "yellow", "darkblue", "yellow", 
"yellow", "darkblue", "darkblue", "red", "darkblue", "darkblue", 
"yellow", "yellow", "darkblue", "yellow", "darkblue", 
"darkblue", "yellow", "darkblue", "red", "darkblue", "darkblue", 
"darkblue", "darkblue", "yellow", "red", "yellow", "red", 
"yellow", "red", "darkblue", "darkblue", "yellow", "yellow", 
"darkblue", "yellow", "yellow", "darkblue", "darkblue", 
"yellow", "darkblue", "red", "yellow", "darkblue", "yellow", 
"red", "yellow", "darkblue", "darkblue", "yellow", "darkblue", 
"yellow", "darkblue", "yellow", "darkblue", "darkblue", 
"darkblue", "yellow", "darkblue", "yellow", "darkblue", 
"darkblue", "darkblue", "darkblue", "darkblue", "darkblue", "yellow", 
"darkblue", "yellow", "yellow", "yellow", "red", "yellow", 
"darkblue", "red", "red", "darkblue", "yellow", "darkblue", 
"darkblue", "yellow", "yellow", "darkblue", "darkblue", 
"darkblue", "yellow", "yellow", "darkblue", "darkblue", 
"darkblue", "darkblue", "darkblue", "yellow", "yellow", 
"yellow", "darkblue", "red", "red", "red", "red", "yellow", 
"yellow", "darkblue", "yellow", "yellow", "darkblue", 
"darkblue", "yellow", "darkblue", "darkblue", "darkblue", 
"yellow", "red", "yellow", "darkblue", "red", "darkblue", 
"darkblue", "yellow", "yellow", "darkblue", "yellow", 
"yellow", "yellow", "red", "darkblue", "red", "yellow", 
"red", "darkblue", "darkblue", "darkblue", "yellow", "darkblue", 
"darkblue", "red", "darkblue", "yellow", "yellow", "yellow", 
"yellow", "darkblue")

注意:由于我在previously发布的问题丢失了我的帐户详细信息,我正在重新发布此问题,管理员请随意合并问题等。

1 个答案:

答案 0 :(得分:1)

所以我需要将col更改为groups

stripplot(locs~factor(rep(1,length(locs)))|dataset,
                  groups=locs.col,
                  pch=19,cex=0.7,
                  jitter.data=T,factor=rep(rnorm(length(locs))),
                  amount=abs(rep(rnorm(length(locs))))*0.05 )