[lattice xyplot] Help needed in help in customizing the panel.abline() function
Hi Girish,
Try this:
disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(x, y, ...) {
panel.abline(v = x[which.max(y)], lty = 2)
panel.xyplot(x, y, ...)
})
-Felix
On 9 December 2010 17:35, Girish A.R. <garamach at gmail.com> wrote:
Hi folks,
I need some help in customizing the abline() function to be used in a
lattice plot. I have attached a reproducible example below.
I need help in the following snippet:
disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(...) {
? ? ? ? ? panel.abline(v = 8, lty = 2)
? ? ? ? ? panel.xyplot(...)
? ? ? })
Is there a way I can give panel.abline() input from a which.max() function?
Essentially I need the vertical line to be drawn at the week_num
corresponding to the max (cnt_gt50pct_disc).
Thanks in advance,
-Girish
===========================================
Lines <- "sku_num week_num ? ?pct_inv_left ? ?cnt_gt50pct_disc
1 ? 1 ? 99.88 ? 47
1 ? 2 ? 99.54 ? 109
1 ? 3 ? 98.7 ? ?260
1 ? 4 ? 97.83 ? 202
1 ? 5 ? 96.53 ? 389
1 ? 6 ? 94.11 ? 450
1 ? 7 ? 90.42 ? 459
1 ? 8 ? 86.63 ? 448
1 ? 9 ? 83.39 ? 411
1 ? 10 ?77 ?478
1 ? 11 ?71.65 ? 476
1 ? 12 ?67.3 ? ?463
1 ? 13 ?62.45 ? 472
1 ? 14 ?52.47 ? 488
1 ? 15 ?40.86 ? 486
1 ? 16 ?31.34 ? 484
1 ? 17 ?23.2 ? ?472
1 ? 18 ?17 ?458
1 ? 19 ?12.66 ? 423
1 ? 20 ?10.18 ? 364
1 ? 21 ?7.6 343
1 ? 22 ?3.09 ? ?343
1 ? 23 ?1.05 ? ?211
2 ? 1 ? 99.94 ? 30
2 ? 2 ? 99.4 ? ?151
2 ? 3 ? 98.85 ? 146
2 ? 4 ? 97.92 ? 274
2 ? 5 ? 97.03 ? 204
2 ? 6 ? 95.59 ? 378
2 ? 7 ? 92.81 ? 452
2 ? 8 ? 89.07 ? 470
2 ? 9 ? 85.11 ? 454
2 ? 10 ?81.68 ? 421
2 ? 11 ?75.34 ? 479
2 ? 12 ?70.05 ? 476
2 ? 13 ?66.11 ? 456
2 ? 14 ?61.85 ? 465
2 ? 15 ?53.2 ? ?485
2 ? 16 ?42.75 ? 486
2 ? 17 ?33.58 ? 481
2 ? 18 ?25 ?477
2 ? 19 ?18.13 ? 450
2 ? 20 ?12.97 ? 416
2 ? 21 ?10.03 ? 343
2 ? 22 ?7.03 ? ?293
2 ? 23 ?2.33 ? ?283
2 ? 24 ?0.77 ? ?116
"
DF <- read.table(con<- textConnection(Lines), skip = 1);
names(DF) <- scan(textConnection(Lines), what = "", nlines = 1) ;
close(con);
require(latticeExtra)
DF$sku_num <- as.factor(DF$sku_num)
disc <- xyplot(cnt_gt50pct_disc ~ week_num|sku_num, data=DF,type =
"h",lwd=2,panel = function(...) {
? ? ? ? ? panel.abline(v = 8, lty = 2)
? ? ? ? ? panel.xyplot(...)
? ? ? })
sales <- xyplot(pct_inv_left ?~ week_num|sku_num, data=swtop16,type =
"l",lwd=2,panel = function(...) {
? ? ? ? ? panel.abline(h = 75, lty = 2)
? ? ? ? ? panel.xyplot(...)
? ? ? })
doubleYScale(disc, sales, style1 = 0, style2 = 2, add.ylab2 = TRUE,text =
c("# stores with gt 50pct disc", "% Unsold"))
--
View this message in context: http://r.789695.n4.nabble.com/lattice-xyplot-Help-needed-in-help-in-customizing-the-panel-abline-function-tp3079656p3079656.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list 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.
Felix Andrews / ??? http://www.neurofractal.org/felix/