[R] add outer strip for levels in lattice plot (useOuterStrips alternative for Lattice)
Luigi Marongiu
marongiu.luigi at gmail.com
Thu Jul 9 01:22:10 CEST 2015
In relation to this question I have prepared a workable example. First
I prepare a dataframe with three variables (Cycle, Target, Rn), then I
plot the results with lattice's xyplot(). I won't use the scales but
only the labels and the panels are NOT indicated by the variable Well.
What I would need to use are instead the vectors row.name and col.name
that can identify each column and row of the plot.
Secondly I create replicates of the row.name and col.name in order to
fit the data and create a second dataframe, then I plot using lattice
extra's useOuterStrips().
However (a) I think the call is wrong anyway, (b) I obtain "Error:
length(dimx) == 2 is not TRUE" (c) I need a package on top of lattice
(d) I might introduce errors during the creation of the second
dataframe.
The requirements remains to create a strip on the top and left side of
the plot to allocate the elements of row.name and col.name possibly
using lattice only.
Thank you for your help.
Luigi
>>>
Line<-c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135,
136, 137, 138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162,
163, 164, 165, 166, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188,
189, 190, 191, 192, 193, 194, 195, 196, 197,
198, 199, 200, 201, 202, 203, 204, 205,
206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 247, 248, 249,
250, 251, 252, 253, 254, 255, 256, 257, 258,
259, 260, 261, 262, 263, 264, 265, 266, 267,
268, 269, 270, 271, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292, 293,
294, 295, 296, 297, 298, 299, 300, 301, 302,
303, 304, 305, 306, 307, 308, 309, 310,
311, 312, 313, 314, 315, 316, 317, 318, 319,
320, 321, 322, 323, 324, 325, 326, 327, 328,
329, 330, 331, 332, 333, 334, 335, 336, 337,
338, 339, 340, 341, 342, 343, 344, 345,
346, 347, 348, 349, 350, 351, 352, 353, 354,
355, 356, 357, 358, 359, 360, 361, 362, 363,
364, 365, 366, 367, 368, 369, 370, 371, 372,
373, 374, 375, 376, 377, 378, 379, 380,
381, 382, 383, 384, 385, 386, 387, 388, 389,
390, 391, 392, 393, 394, 395, 396, 397, 398,
399, 400, 401, 402, 403, 404, 405, 406, 407,
408, 409, 410, 411, 412, 413, 414, 415,
416, 417, 418, 419, 420, 421, 422, 423, 424,
425, 426, 427, 428, 429, 430, 431, 432, 433,
434, 435, 436, 437, 438, 439, 440, 441, 442,
443, 444, 445, 446, 447, 448, 449, 450,
451, 452, 453, 454, 455, 456, 457, 458, 459,
460, 461, 462, 463, 464, 465, 466, 467, 468,
469, 470, 471, 472, 473, 474, 475, 476, 477,
478, 479, 480, 481, 482, 483, 484, 485,
486, 487, 488, 489, 490, 491, 492, 493, 494,
495, 496, 497, 498, 499, 500, 501, 502, 503,
504, 505, 506, 507, 508, 509, 510, 511, 512,
513, 514, 515, 516, 517, 518, 519, 520,
521, 522, 523, 524, 525, 526, 527, 528, 529,
530, 531, 532, 533, 534, 535, 536, 537, 538,
539, 540)
Well<-c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 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12)
Cycle<-c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45)
Target <-c(
rep("alpha",45),
rep("beta", 45),
rep("gamma", 45),
rep("delta", 45),
rep("epsilon", 45),
rep("zeta", 45),
rep("eta", 45),
rep("theta", 45),
rep("iota", 45),
rep("kappa", 45),
rep("lamba", 45),
rep("mu", 45)
)
Rn<-c( 0.728, 0.735, 0.749, 0.758, 0.77, 0.778,
0.78, 0.784, 0.786, 0.785, 0.786, 0.786, 0.785,
0.785, 0.784, 0.783, 0.784, 0.786, 0.786, 0.787,
0.789, 0.786, 0.784, 0.786, 0.786, 0.785, 0.784,
0.785, 0.786, 0.784, 0.784, 0.78, 0.781, 0.779,
0.78, 0.78, 0.78, 0.781, 0.781, 0.78, 0.78,
0.781, 0.781, 0.78, 0.781, 0.695, 0.712, 0.751,
0.784, 0.81, 0.831, 0.852, 0.867, 0.877, 0.889,
0.896, 0.902, 0.908, 0.912, 0.912, 0.915, 0.919,
0.916, 0.918, 0.92, 0.917, 0.914, 0.917, 0.914,
0.914, 0.913, 0.913, 0.91, 0.908, 0.906, 0.902,
0.9, 0.901, 0.897, 0.896, 0.895, 0.896, 0.892,
0.89, 0.889, 0.89, 0.888, 0.889, 0.885, 0.886,
1.701, 1.702, 1.69, 1.678, 1.666, 1.65, 1.642,
1.632, 1.623, 1.616, 1.605, 1.598, 1.591, 1.582,
1.575, 1.568, 1.561, 1.556, 1.553, 1.549, 1.546,
1.541, 1.536, 1.531, 1.529, 1.526, 1.524, 1.522,
1.52, 1.517, 1.516, 1.514, 1.512, 1.512, 1.509,
1.509, 1.506, 1.505, 1.505, 1.508, 1.513, 1.508,
1.506, 1.507, 1.503, 0.761, 0.774, 0.797, 0.817,
0.833, 0.844, 0.85, 0.856, 0.864, 0.867, 0.869,
0.873, 0.874, 0.875, 0.873, 0.872, 0.872, 0.87,
0.866, 0.865, 0.864, 0.864, 0.86, 0.857, 0.855,
0.852, 0.851, 0.849, 0.845, 0.843, 0.842, 0.84,
0.835, 0.833, 0.83, 0.827, 0.825, 0.826, 0.824,
0.821, 0.82, 0.818, 0.817, 0.816, 0.813, 0.982,
0.988, 0.998, 1.009, 1.015, 1.018, 1.021, 1.023,
1.023, 1.02, 1.016, 1.015, 1.009, 1.005, 1.003,
1, 0.995, 0.989, 0.985, 0.981, 0.975, 0.969,
0.964, 0.96, 0.956, 0.952, 0.948, 0.944, 0.94,
0.935, 0.932, 0.927, 0.924, 0.921, 0.918, 0.915,
0.91, 0.907, 0.904, 0.901, 0.898, 0.896, 0.892,
0.889, 0.888, 1.14, 1.133, 1.117, 1.105, 1.096,
1.086, 1.074, 1.063, 1.052, 1.042, 1.033, 1.024,
1.015, 1.006, 0.999, 0.993, 0.987, 0.982, 0.975,
0.969, 0.965, 0.96, 0.955, 0.952, 0.947, 0.944,
0.943, 0.939, 0.935, 0.933, 0.93, 0.927, 0.925,
0.921, 0.919, 0.919, 0.917, 0.917, 0.915, 0.912,
0.912, 0.912, 0.909, 0.907, 0.907, 1.304, 1.31,
1.325, 1.338, 1.349, 1.355, 1.359, 1.36, 1.361,
1.362, 1.359, 1.353, 1.344, 1.335, 1.331, 1.323,
1.315, 1.308, 1.3, 1.292, 1.284, 1.276, 1.268,
1.262, 1.256, 1.25, 1.245, 1.241, 1.234, 1.228,
1.222, 1.216, 1.213, 1.208, 1.205, 1.2, 1.197,
1.192, 1.189, 1.186, 1.184, 1.182, 1.181, 1.178,
1.178, 0.802, 0.801, 0.801, 0.8, 0.799, 0.797,
0.794, 0.791, 0.785, 0.781, 0.777, 0.772, 0.766,
0.76, 0.756, 0.753, 0.751, 0.746, 0.742, 0.739,
0.735, 0.732, 0.728, 0.726, 0.725, 0.722, 0.718,
0.717, 0.716, 0.715, 0.71, 0.709, 0.711, 0.71,
0.709, 0.709, 0.709, 0.709, 0.708, 0.709, 0.71,
0.71, 0.711, 0.711, 0.712, 1.209, 1.206, 1.204,
1.202, 1.197, 1.186, 1.175, 1.165, 1.154, 1.143,
1.133, 1.12, 1.11, 1.105, 1.098, 1.091, 1.085,
1.078, 1.072, 1.067, 1.063, 1.054, 1.049, 1.048,
1.04, 1.036, 1.033, 1.029, 1.027, 1.024, 1.021,
1.019, 1.017, 1.013, 1.01, 1.008, 1.006, 1.005,
1.004, 1.002, 1.002, 1.001, 1, 0.998, 0.995,
2.936, 2.942, 2.946, 2.951, 2.956, 2.956, 2.968,
2.964, 2.953, 2.945, 2.939, 2.929, 2.919, 2.909,
2.902, 2.893, 2.882, 2.871, 2.857, 2.847, 2.835,
2.825, 2.819, 2.806, 2.795, 2.787, 2.781, 2.766,
2.761, 2.752, 2.749, 2.74, 2.731, 2.722, 2.718,
2.711, 2.705, 2.7, 2.693, 2.69, 2.686, 2.676,
2.672, 2.668, 2.667, 1.032, 1.033, 1.031, 1.033,
1.031, 1.029, 1.025, 1.02, 1.019, 1.016, 1.012,
1.008, 1.007, 1.011, 1.015, 1.032, 1.068, 1.124,
1.209, 1.327, 1.472, 1.632, 1.8, 1.971, 2.14,
2.302, 2.459, 2.612, 2.754, 2.886, 3.008, 3.122,
3.218, 3.306, 3.39, 3.472, 3.547, 3.613, 3.674,
3.731, 3.772, 3.81, 3.84, 3.86, 3.882, 0.808,
0.808, 0.808, 0.807, 0.805, 0.804, 0.802, 0.801,
0.798, 0.796, 0.794, 0.79, 0.788, 0.785, 0.781,
0.78, 0.777, 0.774, 0.772, 0.771, 0.769, 0.767,
0.767, 0.766, 0.766, 0.764, 0.764, 0.765, 0.762,
0.762, 0.76, 0.759, 0.759, 0.758, 0.758, 0.758,
0.756, 0.754, 0.754, 0.753, 0.754, 0.755, 0.753,
0.754, 0.753)
my.data <- as.data.frame(cbind(Line, Well, Target, Rn))
L <- c(6,2)
row.name <- c("A", "B")
col.name <- 1:6
library("lattice")
xyplot(Rn ~ Cycle | Well,
data = my.data,
groups = Well,
ylab= "Y axis",
xlab="X axis",
main="Title",
scales = list(
x = list(draw = FALSE),
y = list(draw = FALSE),
relation="same"
),
as.table = TRUE,
layout = L,
par.settings = list(
strip.background=list(col="white"),
axis.text = list(cex = 0.6),
par.xlab.text = list(cex = 0.75),
par.ylab.text = list(cex = 0.75),
par.main.text = list(cex = 0.8),
superpose.symbol = list(pch = ".", cex = 1)
),
strip = FALSE,
type = "l",
col = 3,
panel = panel.superpose
)
ROW <- c(rep(row.name[1], 45*6), rep(row.name[2], 45*6))
CO <- c(rep(col.name[1], 45),
rep(col.name[2], 45),
rep(col.name[3], 45),
rep(col.name[4], 45),
rep(col.name[5], 45),
rep(col.name[6], 45)
)
COL <- rep(CO,2)
new.data <- cbind(my.data, ROW, COL)
head(new.data, 200)
useOuterStrips(
xyplot(Rn ~ Cycle | Well,
data = my.data,
groups = Well,
ylab= "Y axis",
xlab="X axis",
main="Title",
scales = list(
x = list(draw = FALSE),
y = list(draw = FALSE),
relation="same"
),
as.table = TRUE,
layout = L,
par.settings = list(
strip.background=list(col="white"),
axis.text = list(cex = 0.6),
par.xlab.text = list(cex = 0.75),
par.ylab.text = list(cex = 0.75),
par.main.text = list(cex = 0.8),
superpose.symbol = list(pch = ".", cex = 1)
),
strip = FALSE,
type = "l",
col = 3,
panel = panel.superpose
),
c(ROW,COL))
On Tue, Jul 7, 2015 at 12:19 AM, Duncan Mackay <dulcalma at bigpond.com> wrote:
> Hi Luigi
>
> Not exactly sure what you want
>
> Have a look at
> https://stat.ethz.ch/pipermail/r-help/2007-May/132785.html
> and
> https://stat.ethz.ch/pipermail/r-help/2007-July/135551.html
>
> otherwise have a look at ?trellis.focus and
> https://stat.ethz.ch/pipermail/r-help/2006-July/109585.html
>
> failing that ?gridRect and ?gridText from library(grid)
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mackay at northnet.com.au
>
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi
> Marongiu
> Sent: Monday, 6 July 2015 09:56
> To: r-help
> Subject: [R] add outer strip for levels in lattice plot (useOuterStrips
> alternative for Lattice)
>
> Dear all,
> I would like to add an outer strip or something like that on a lattice
> plot I am making. Such plot contains 384 cells and, since I am not
> interested in the axis values, I set:
> scales = list(
> x = list(draw = FALSE),
> y = list(draw = FALSE),
> relation="same"
> ),
> on a xyplot from the LATTICE package.
> Nevertheless there are axis labels which run like:
> ylab= "Y axis",
> xlab= "X axis",
> I would like to place some more information regarding the individual
> cells thus I would like to draw a sort of extra axis labels that are
> similar to the outer strip of the LATTICE_EXTRA package, that is
> markers placed between the axis labels and the axis values and
> centered for each cells, typically placed on the top and left sides of
> the plot. This is performed by the useOuterStrips function but:
> a) LatticeExtra is not in the CRAN repository thus I have to install
> it through a more laborious approach which makes LatticeExtra less
> direct than Lattice
> b) useOuterStrips uses information directly from the data whereas I
> will have to provide the extra information from ad hoc vectors not
> present in the data set.
>
> The question therefore is: is there a way to write text from a vector
> in the top and left corners of a lattice xyplot and place the
> individual elements at the centre of the rows and columns that compose
> the graph?
>
> Many thanks,
> Luigi
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list