How to plot coefficients with robust standard errors? - r

I have this LSDV model using the "lm()" function and adding the country dummy variables minus the intercept. Then I made robust standard errors in order to fix heteroskedasticity and autocorrelation:
msubv2 <- lm(subv ~ preelec + elec + postelec + ideo + ali +
crec_pib + pob + pob16 + pob64 + factor(ccaa)-1, data = datos)
rsecoef_msubv2 <- coeftest(msubv2, vcovHAC(msubv2))
This is the code I used in order to implement the new coefficients in a regression output with stargazer() by the way:
cov12 <- vcovHAC(msubv2)
rsesubv2 <- sqrt(diag(cov12))
Now I want to plot these new coefficients of the explanatory variables "preelec", "elec" and "postelec" using either ggplot2() or coefplot() from the namesake package. However, as my object which contains the new coefficients is not an "lm" object, when I use those functions I get an error.
Hence, I just want to know how can I convert the object rsecoef_msubv2 into an "lm" object, or just another way to plot the coefficients for those 3 variables.
P.S. Ok, so this is a subset of my data. It must be converted into a panel data
structure(list(ccaa = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L,
12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L), .Label = c("ANDALUCIA",
"ARAGON", "ASTURIAS", "BALEARES", "CANARIAS", "CANTABRIA", "CASTILLA LA-MANCHA",
"CASTILLA Y LEÓN", "CATALUÑA", "EXTREMADURA", "GALICIA", "LA RIOJA",
"MADRID", "MURCIA", "NAVARRA", "PAIS VASCO", "VALENCIA"), class = "factor"),
year = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1986", "1987",
"1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995",
"1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003",
"2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011",
"2012", "2013", "2014", "2015", "2016", "2017"), class = "factor"),
ccaa_year = structure(c("AND86", "AND87", "ARA86", "ARA87",
"AST86", "AST87", "BAL86", "BAL87", "ISC86", "ISC87", "CANT86",
"CANT87", "CLM86", "CLM87", "CYL86", "CYL87", "CAT86", "CAT87",
"EXT86", "EXT87", "GAL86", "GAL87", "RIO86", "RIO87", "MAD86",
"MAD87", "MUR86", "MUR87", "NAV86", "NAV87", "PAV86", "PAV87",
"VAL86", "VAL87"), index = structure(list(ccaa = 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, 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, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L), .Label = c("ANDALUCIA", "ARAGON",
"ASTURIAS", "BALEARES", "CANARIAS", "CANTABRIA", "CASTILLA LA-MANCHA",
"CASTILLA Y LEÓN", "CATALUÑA", "EXTREMADURA", "GALICIA",
"LA RIOJA", "MADRID", "MURCIA", "NAVARRA", "PAIS VASCO",
"VALENCIA"), class = "factor"), year = structure(c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L), .Label = c("1986",
"1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994",
"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002",
"2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010",
"2011", "2012", "2013", "2014", "2015", "2016", "2017"), class = "factor")), row.names = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L,
75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L,
99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L,
109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L,
119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L,
129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L,
139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L,
149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L,
169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L,
179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L,
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L,
199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L,
209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L,
219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L,
229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L,
239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L,
259L, 260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L,
269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L,
279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L,
321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L,
331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L,
341L, 342L, 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L,
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L,
361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L,
371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L,
381L, 382L, 383L, 384L, 513L, 514L, 515L, 516L, 517L, 518L,
519L, 520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L, 528L,
529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L,
539L, 540L, 541L, 542L, 543L, 544L, 385L, 386L, 387L, 388L,
389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L,
399L, 400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L,
409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L,
419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L, 428L,
429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L,
439L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L,
449L, 450L, 451L, 452L, 453L, 454L, 455L, 456L, 457L, 458L,
459L, 460L, 461L, 462L, 463L, 464L, 465L, 466L, 467L, 468L,
469L, 470L, 471L, 472L, 473L, 474L, 475L, 476L, 477L, 478L,
479L, 480L, 481L, 482L, 483L, 484L, 485L, 486L, 487L, 488L,
489L, 490L, 491L, 492L, 493L, 494L, 495L, 496L, 497L, 498L,
499L, 500L, 501L, 502L, 503L, 504L, 505L, 506L, 507L, 508L,
509L, 510L, 511L, 512L, 289L, 290L, 291L, 292L, 293L, 294L,
295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 303L, 304L,
305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L,
315L, 316L, 317L, 318L, 319L, 320L), class = c("pindex",
"data.frame")), class = c("pseries", "character")), subv = structure(c(16.7302560676507,
20.4606384605254, 10.3964123452188, 6.36288798106429, 9.16543765426987,
8.40335369638951, 7.95058549475298, 7.07913989487299, 21.1288836451444,
18.6147451720256, 11.613581886766, 7.75476195855383, 24.3052882852147,
21.1325248124902, 7.19278302770739, 7.20350705287662, 25.860092626368,
23.3847976914879, 11.0315837047611, 17.5546273201597, 14.0537729379123,
14.8129830488661, 10.2404482920113, 6.98585616360406, 29.2092515156566,
17.1150774779986, 8.82174329305509, 7.9138138292632, 12.9945592447864,
13.0334015804209, 1.31541109940362, 2.11013964638404, 17.6289233833167,
19.691143771018), index = structure(list(ccaa = 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, 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, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L), .Label = c("ANDALUCIA", "ARAGON",
"ASTURIAS", "BALEARES", "CANARIAS", "CANTABRIA", "CASTILLA LA-MANCHA",
"CASTILLA Y LEÓN", "CATALUÑA", "EXTREMADURA", "GALICIA",
"LA RIOJA", "MADRID", "MURCIA", "NAVARRA", "PAIS VASCO",
"VALENCIA"), class = "factor"), year = structure(c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L), .Label = c("1986",
"1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994",
"1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002",
"2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010",
"2011", "2012", "2013", "2014", "2015", "2016", "2017"), class = "factor")), row.names = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L,
75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L,
99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L,
109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L,
119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L,
129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L,
139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L,
149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L,
169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L,
179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L,
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L,
199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L,
209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L,
219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L,
229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L,
239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L,
259L, 260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L,
269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L,
279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L,
321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L,
331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L,
341L, 342L, 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L,
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L,
361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L,
371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L,
381L, 382L, 383L, 384L, 513L, 514L, 515L, 516L, 517L, 518L,
519L, 520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L, 528L,
529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L,
539L, 540L, 541L, 542L, 543L, 544L, 385L, 386L, 387L, 388L,
389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L,
399L, 400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L,
409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L,
419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L, 428L,
429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L,
439L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L,
449L, 450L, 451L, 452L, 453L, 454L, 455L, 456L, 457L, 458L,
459L, 460L, 461L, 462L, 463L, 464L, 465L, 466L, 467L, 468L,
469L, 470L, 471L, 472L, 473L, 474L, 475L, 476L, 477L, 478L,
479L, 480L, 481L, 482L, 483L, 484L, 485L, 486L, 487L, 488L,
489L, 490L, 491L, 492L, 493L, 494L, 495L, 496L, 497L, 498L,
499L, 500L, 501L, 502L, 503L, 504L, 505L, 506L, 507L, 508L,
509L, 510L, 511L, 512L, 289L, 290L, 291L, 292L, 293L, 294L,
295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 303L, 304L,
305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L,
315L, 316L, 317L, 318L, 319L, 320L), class = c("pindex",
"data.frame")), class = c("pseries", "numeric")), elec = c(1L,
0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L,
0L, 0L, 1L), preelec = c(0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L,
0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L), postelec = c(0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L), ideo = c(0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L,
1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L), ali = c(1L, 1L,
1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L,
0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,
1L, 1L)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -34L), groups = structure(list(ccaa = structure(1:17, .Label = c("ANDALUCIA",
"ARAGON", "ASTURIAS", "BALEARES", "CANARIAS", "CANTABRIA", "CASTILLA LA-MANCHA",
"CASTILLA Y LEÓN", "CATALUÑA", "EXTREMADURA", "GALICIA", "LA RIOJA",
"MADRID", "MURCIA", "NAVARRA", "PAIS VASCO", "VALENCIA"), class = "factor"),
.rows = structure(list(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), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -17L), .drop = TRUE))
P.S. I just need something like this
P.S. Finally I think I found a solution. The coefficients plot can be performed with the fuction "ggcoef" from the "GGally" package, which enables us to include as an object the coeftest() argument. Then we can procede like this:
First we create an object for our coeftest():
matrix_coeftestmsubv2 <- coeftest(msubv2, vcovHAC(msubv2))
After that we just create the plot with "ggcoef()":
ggcoef(matrix_coefmsubv2) + coord_flip()
Nevertheless, I still have some doubts regarding how to keep certain variables from the model, how to order them in the X Axis and how to add a line to connect the coefficients points, but I think I'll make a new post in order to get an answer.

So I found a definitive solution, I'm going to share it with you all. The function we need is dwplot() which belongs to the "dotwhisker" package. This one allows us to include a "coeftest" object and uses "ggplot2" to custom the graph easily. However, I recommend to convert the coeftest object into a dataframe because it makes it easier to delete the variables we don't need.
First we need to convert the object rsecoef_msubv2 into a dataframe:
library(dotwhisker)
rsecoef_msubv2 <- as.data.frame(rsecoef_msubv2)
After that we delete the rows we don't need, in my case:
tidycoefisubv <- tidycoefisubv[-c(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26), ]
Finally we just create the plot using "dwplot". In this example I flipped the position of the axis, changed the color of the background and the font and size of the text of both axis.
dwplot(tidycoefisubv, vars_order = c("Postelectoral", "Electoral", "Preelectoral")) +
coord_flip() + theme_bw() + theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), text = element_text(size = 10),
axis.text.y = element_text(size=10, color="black"), axis.text.x = element_text(size=10,
color="black"),legend.position = "none") + labs(x = "Transferencias per cápita", y = NULL)
And this is the result:

Related

Arranging time stamped data in chronological order

An output table of one of my codes looks like this:
> head(act.byHour_corr)
hour date activity
1: 0 Activity on 6/20/2018 59
2: 1 Activity on 6/20/2018 74
3: 2 Activity on 6/20/2018 2683
4: 3 Activity on 6/20/2018 4341
5: 4 Activity on 6/20/2018 3676
6: 5 Activity on 6/20/2018 2143
The column hour represents the hours of the day from 0 to 23 and the data in date is chronologically organized. Unfortunately, when the data comes to the point where the next month 7/dd/2018 is reached, date is not chronologically organized anymore:
> head(act.byHour_corr[287:293])
hour date activity
1: 22 Activity on 7/1/2018 400
2: 23 Activity on 7/1/2018 201
3: 0 Activity on 7/10/2018 705
4: 1 Activity on 7/10/2018 47
5: 2 Activity on 7/10/2018 605
6: 3 Activity on 7/10/2018 257
You can see that 7/10/2018 and its associated values come after 7/1/2018 instead of that being 7/2/2018.
If that helps I can provide my dataset below:
> dput(act.byHour_corr)
structure(list(hour = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L), date = 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, 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, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L,
32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L,
33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L,
33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 34L, 34L, 34L,
34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L,
34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L,
35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L,
35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L,
36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L,
36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L,
37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L,
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L,
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 41L, 41L, 41L, 41L,
41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L,
41L, 41L, 41L, 41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 42L, 42L, 42L, 42L), class = "factor", .Label = c("Activity on 6/20/2018",
"Activity on 6/21/2018", "Activity on 6/22/2018", "Activity on 6/23/2018",
"Activity on 6/24/2018", "Activity on 6/25/2018", "Activity on 6/26/2018",
"Activity on 6/27/2018", "Activity on 6/28/2018", "Activity on 6/29/2018",
"Activity on 6/30/2018", "Activity on 7/1/2018", "Activity on 7/10/2018",
"Activity on 7/11/2018", "Activity on 7/12/2018", "Activity on 7/13/2018",
"Activity on 7/14/2018", "Activity on 7/15/2018", "Activity on 7/16/2018",
"Activity on 7/17/2018", "Activity on 7/18/2018", "Activity on 7/19/2018",
"Activity on 7/2/2018", "Activity on 7/20/2018", "Activity on 7/21/2018",
"Activity on 7/22/2018", "Activity on 7/23/2018", "Activity on 7/24/2018",
"Activity on 7/25/2018", "Activity on 7/26/2018", "Activity on 7/27/2018",
"Activity on 7/28/2018", "Activity on 7/29/2018", "Activity on 7/3/2018",
"Activity on 7/30/2018", "Activity on 7/31/2018", "Activity on 7/4/2018",
"Activity on 7/5/2018", "Activity on 7/6/2018", "Activity on 7/7/2018",
"Activity on 7/8/2018", "Activity on 7/9/2018")), activity = c(59L,
74L, 2683L, 4341L, 3676L, 2143L, 3890L, 3887L, 1299L, 1492L,
3449L, 2200L, 1563L, 4346L, 5329L, 3037L, 1462L, 668L, 383L,
483L, 288L, 2765L, 3354L, 1783L, 241L, 301L, 261L, 3683L, 4356L,
3736L, 2810L, 1841L, 3146L, 609L, 2998L, 4059L, 3690L, 3735L,
1343L, 2087L, 894L, 341L, 240L, 2113L, 1684L, 3115L, 2890L, 138L,
21L, 451L, 96L, 2918L, 2279L, 2282L, 4992L, 698L, 427L, 581L,
1248L, 2184L, 1980L, 2364L, 568L, 2477L, 525L, 433L, 974L, 501L,
760L, 67L, 297L, 1198L, 2L, 39L, 42L, 1182L, 1749L, 2144L, 3123L,
1170L, 1641L, 1112L, 1526L, 1199L, 534L, 1481L, 2388L, 2756L,
392L, 112L, 390L, 107L, 709L, 1122L, 1562L, 451L, 8L, 74L, 0L,
158L, 780L, 3118L, 3292L, 2759L, 3121L, 2051L, 2387L, 900L, 627L,
904L, 4283L, 3726L, 1273L, 977L, 326L, 163L, 1915L, 1073L, 1021L,
545L, 36L, 22L, 3L, 55L, 124L, 22L, 4093L, 2867L, 3649L, 2550L,
1590L, 636L, 2571L, 998L, 1066L, 2967L, 1211L, 51L, 1188L, 1413L,
714L, 177L, 132L, 29L, 22L, 43L, 0L, 90L, 1094L, 1655L, 2643L,
2108L, 2249L, 2453L, 2857L, 915L, 437L, 1142L, 2193L, 2993L,
1139L, 1549L, 652L, 580L, 970L, 674L, 211L, 206L, 167L, 63L,
1L, 786L, 617L, 1575L, 2237L, 1302L, 1149L, 2009L, 2234L, 1263L,
1259L, 2017L, 1641L, 2683L, 1184L, 449L, 65L, 956L, 1538L, 1287L,
593L, 362L, 594L, 1172L, 25L, 445L, 921L, 1812L, 2235L, 1153L,
422L, 1084L, 2158L, 1610L, 845L, 1187L, 2528L, 2161L, 976L, 19L,
747L, 570L, 576L, 19L, 304L, 2L, 301L, 7L, 399L, 494L, 723L,
1088L, 771L, 85L, 1338L, 866L, 384L, 1356L, 2862L, 3805L, 2142L,
1655L, 249L, 235L, 3L, 0L, 283L, 981L, 634L, 1370L, 9L, 137L,
33L, 975L, 1690L, 1639L, 985L, 210L, 1266L, 2135L, 2080L, 1704L,
2449L, 3133L, 1055L, 3222L, 1152L, 173L, 858L, 188L, 700L, 330L,
905L, 1232L, 1006L, 5L, 21L, 520L, 1162L, 1771L, 2463L, 1403L,
1353L, 1938L, 2388L, 4133L, 900L, 2660L, 3504L, 3946L, 1956L,
818L, 604L, 937L, 373L, 48L, 400L, 201L, 705L, 47L, 605L, 257L,
1359L, 41L, 1019L, 1426L, 2219L, 1179L, 1624L, 537L, 421L, 1747L,
2941L, 2921L, 1046L, 283L, 476L, 218L, 59L, 389L, 657L, 1293L,
24L, 455L, 6L, 1232L, 2264L, 1152L, 600L, 11L, 980L, 1519L, 2004L,
1933L, 2161L, 1386L, 1883L, 2978L, 1385L, 104L, 1309L, 2L, 364L,
550L, 0L, 1433L, 1634L, 27L, 860L, 1095L, 1102L, 132L, 582L,
710L, 1368L, 2470L, 2944L, 1030L, 1286L, 387L, 2590L, 2449L,
743L, 134L, 274L, 205L, 360L, 627L, 1357L, 591L, 216L, 143L,
70L, 2L, 477L, 42L, 81L, 304L, 2827L, 2437L, 2002L, 688L, 935L,
812L, 404L, 1098L, 1157L, 857L, 466L, 215L, 714L, 269L, 1223L,
8L, 1L, 635L, 6L, 1797L, 1363L, 246L, 704L, 1089L, 943L, 2251L,
813L, 2643L, 1657L, 18L, 1132L, 2884L, 1044L, 149L, 1146L, 68L,
1227L, 1189L, 129L, 1291L, 7L, 9L, 1299L, 389L, 288L, 157L, 0L,
324L, 248L, 915L, 795L, 598L, 733L, 308L, 2760L, 2874L, 1903L,
499L, 73L, 31L, 1146L, 920L, 852L, 2L, 104L, 564L, 16L, 1903L,
675L, 1859L, 720L, 1017L, 4L, 2114L, 2264L, 1152L, 935L, 1691L,
1031L, 2568L, 2035L, 226L, 18L, 1716L, 249L, 717L, 635L, 919L,
1436L, 16L, 17L, 1891L, 1175L, 74L, 435L, 377L, 718L, 619L, 439L,
1373L, 2154L, 2481L, 763L, 2084L, 910L, 641L, 669L, 737L, 793L,
1471L, 12L, 96L, 6L, 13L, 81L, 1227L, 1685L, 260L, 238L, 575L,
930L, 330L, 1139L, 785L, 1110L, 1007L, 1770L, 2824L, 729L, 776L,
602L, 550L, 1432L, 567L, 197L, 107L, 38L, 648L, 264L, 911L, 2239L,
1063L, 9L, 1336L, 1235L, 628L, 1722L, 1028L, 1393L, 44L, 2110L,
1719L, 666L, 127L, 885L, 788L, 1274L, 765L, 1094L, 38L, 876L,
505L, 162L, 775L, 1567L, 896L, 1648L, 995L, 2574L, 1080L, 997L,
1881L, 1375L, 1283L, 2156L, 2384L, 982L, 33L, 20L, 761L, 241L,
696L, 133L, 915L, 514L, 14L, 59L, 1081L, 1266L, 359L, 1055L,
280L, 123L, 2251L, 2302L, 1116L, 2750L, 764L, 1377L, 2776L, 970L,
814L, 10L, 1364L, 1137L, 279L, 10L, 605L, 279L, 596L, 12L, 1443L,
1463L, 1426L, 132L, 924L, 379L, 693L, 137L, 219L, 884L, 194L,
450L, 1204L, 487L, 578L, 445L, 9L, 823L, 2L, 1212L, 12L, 200L,
9L, 152L, 1062L, 1926L, 1156L, 1951L, 1735L, 753L, 570L, 362L,
813L, 756L, 1403L, 308L, 1895L, 325L, 768L, 666L, 33L, 634L,
1294L, 819L, 39L, 579L, 8L, 657L, 438L, 521L, 896L, 2560L, 1383L,
819L, 1293L, 2257L, 476L, 1850L, 759L, 2482L, 1513L, 789L, 78L,
329L, 43L, 50L, 1583L, 342L, 0L, 495L, 13L, 127L, 1415L, 1534L,
939L, 2315L, 649L, 154L, 2838L, 1462L, 2255L, 1058L, 316L, 1825L,
2391L, 324L, 185L, 813L, 997L, 830L, 407L, 796L, 624L, 1002L,
6L, 86L, 1091L, 1951L, 8L, 1863L, 2555L, 799L, 749L, 2386L, 1893L,
524L, 846L, 2263L, 2266L, 779L, 88L, 380L, 1495L, 1985L, 3L,
1462L, 1450L, 1L, 19L, 967L, 1565L, 1066L, 9L, 99L, 4L, 1889L,
1848L, 1924L, 471L, 1357L, 626L, 1465L, 1787L, 1437L, 115L, 322L,
717L, 1639L, 990L, 1029L, 1112L, 372L, 8L, 256L, 1679L, 1209L,
2246L, 2153L, 1762L, 1883L, 1551L, 998L, 728L, 1274L, 888L, 508L,
2357L, 452L, 1167L, 2385L, 3280L, 320L, 1130L, 878L, 583L, 799L,
4L, 61L, 394L, 1237L, 854L, 68L, 379L, 2910L, 3088L, 1011L, 840L,
1024L, 2496L, 3079L, 2830L, 1841L, 1772L, 595L, 65L, 584L, 2110L,
1966L, 473L, 21L, 847L, 293L, 881L, 840L, 1912L, 683L, 1362L,
1276L, 3131L, 3110L, 1773L, 1077L, 1437L, 769L, 2311L, 1623L,
562L, 42L, 1791L, 1318L, 1230L, 202L, 2630L, 623L, 918L, 48L,
523L, 721L, 1624L, 1047L, 1783L, 313L, 1042L, 2211L, 2430L, 1770L,
1610L, 2814L, 2460L, 1770L, 25L, 709L, 416L, 709L, 998L, 921L,
89L, 1174L, 396L, 52L, 2261L, 1237L, 56L, 927L, 2491L, 3180L,
352L, 81L, 2072L, 3207L, 2394L, 600L, 3280L, 1745L, 147L, 1L,
1544L, 350L, 2198L, 1833L, 55L, 0L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
258L, 1242L, 75L, 1131L, 893L, 402L, 381L, 51L, 15L, 47L, 762L,
777L, 479L, 2416L, 3639L, 1991L, 202L, 1054L, 917L, 1565L, 503L,
61L, 44L, 2103L, 2212L, 352L, 1L, 666L, 351L, 1321L, 7L, 1010L,
1222L, 1080L, 1643L, 1101L, 188L, 2793L, 1548L, 1811L, 1807L,
51L, 788L, 1108L, 1157L, 1038L, 225L, 454L, 441L, 376L, 444L,
5L, 501L, 579L, 1253L, 1600L, 1051L, 498L, 2217L, 2362L, 2425L,
1220L, 2037L, 2684L, 799L, 471L, 139L, 545L, 1117L, 177L, 487L,
1420L, 692L, 303L, 736L, 750L, 1386L, 926L, 30L, 862L, 1912L,
2731L, 1123L, 1160L, 2892L, 1634L, 585L, 3473L, 2243L, 441L,
399L, 1482L, 111L, 455L, 1315L, 691L, 1428L, 96L, 52L, 258L,
1135L, 1727L, 448L, 2148L, 358L, 2180L, 1519L, 2634L, 828L, 1212L,
1052L, 2851L, 902L, 171L, 236L, 3L, 727L, 1366L, 637L, 43L, 0L,
1320L, 146L, 664L, 862L, 663L, 227L, 227L, 995L, 743L, 1793L,
2421L, 1346L, 1874L, 2182L, 1333L, 1967L, 1023L, 297L, 340L,
1469L, 10L, 213L, 805L)), row.names = c(NA, -1008L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x0000000002641ef0>)
Hope I can get some help to organize the data chronologically for the full dataset. Any input is appreciated.
This should help!
act.byHour_corr$date <- as.Date(gsub('Activity on ', '', act.byHour_corr$date),
format = '%m/%d/%Y')
act.byHour_corr <- act.byHour_corr[order(act.byHour_corr$date),]
It removes the 'Activity on' portion of the column. Does that work, or do you need to keep the 'Activity on' part?
Add hour to you data:
library(data.table)
library(lubridate)
library(stringr)
act.byHour_corr[, data_hour:=(paste0(date," ", str_pad(hour, 2, "left",0),":00"))]
act.byHour_corr[, data_hour:=mdy_hm(data_hour)]
act.byHour_corr[order(data_hour)]

geom_path with discrete boxplot data

Finally run out of ideas and links I could find to try and explain this so I need some help!
I'm trying to add a step-function to a ggplot chart using the cumSeg package. I did this successfully in this previous question, so I'm used to the usage of the function etc.
When I made the plot in that thread, it was fairly simple, just using an x vs y barplot for the mean values of x, and I added on error bars myself afterwards (thus it was a 16 x 2 dataframe).
I want to re-create this plot, but using sequential boxplots instead of bars, which I have done, using the raw data this time, which is ~250 observations in 16 factors (same factors as before).
Now when I try to add a geom_line,path or step it's complaining about the dimensions of the data not matching, because even though there are 16 factors/boxplots, there are now no longer 16 observations (Error: Aesthetics must be either length 1 or the same as the data (249): x, y, colour, group, fill)
To calculate the step function, I give it the means of each of the 16, which returns a 16-member vector, not ~250 (obviously).
How can I add the step function on to the box plot so that it understands it should pertain to the 16 factor values? I can't work out if it's a problem with the dataframe or how I'm giving it to ggplot.
I tried specifying it in a second dataframe, and passing it as geom_path(data=df2) instead of inheriting the main plots data, as in this question, but it still complains (Error: Aesthetics must be either length 1 or the same as the data (16): x, y, colour, group (the code below is in this form still)
data.melt <- melt(t(infile)
operon_gc <- 0.408891366
opgc_stdev <- 0.015712091
genome_gc <- 0.425031611
gengc_stdev <- 0.007587437
stepfunc <- jumpoints(y=aggregate(melted_data$value~melted_data$Var1, simplify=TRUE, FUN="mean")$`melted_data$value`, k=1, output="1")
func_data <- data.frame(x = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), y = stepfunc$fitted.values)
# Make boxplot
bp <- ggplot(melted_data, aes(x=Var1, y=value*100, fill=Var1)) + theme_bw()
#bp <- bp + scale_x_discrete(name = "Locus") + scale_y_continuous(name="GC Content (%)")
bp <- bp + geom_rect(xmin=0, xmax=17,
ymin=(operon_gc-opgc_stdev)*100,
ymax=(operon_gc+opgc_stdev)*100,
fill = "grey79", alpha=0.05)
bp <- bp + geom_rect(xmin=0, xmax=17,
ymin=(genome_gc-gengc_stdev)*100,
ymax=(genome_gc+gengc_stdev)*100,
fill = "beige", alpha=.08)
bp <- bp + geom_abline(intercept=genome_gc*100, slope=0,
colour="gray14", linetype=3)
bp <- bp + geom_abline(intercept=operon_gc*100, slope=0,
colour="gray14", linetype=3)
bp <- bp + geom_boxplot(alpha = 0.7)
bp <- bp + scale_color_manual(values = c("GC Step Fit"="red"), guides(color="Regression"))
bp <- bp + geom_path(linetype=4, size=0.9, aes(x=func_data$x,
y=func_data$y,
color="GC Step Fit",
group=1))
bp <- bp + theme(legend.position="bottom",
legend.direction="horizontal",
axis.text.x = element_text(angle=45, hjust=1)) + guides(fill=guide_legend(title="", nrow = 1))
bp
Data
> dput(func_data)
structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16), y = c(0.452456815737206, 0.452456815737206, 0.452456815737206,
0.452456815737206, 0.452456815737206, 0.452456815737206, 0.452456815737206,
0.452456815737206, 0.452456815737206, 0.452456815737206, 0.452456815737206,
0.375047391939972, 0.375047391939972, 0.375047391939972, 0.375047391939972,
0.375047391939972)), .Names = c("x", "y"), row.names = c(NA,
-16L), class = "data.frame")
> dput(melted_data)
structure(list(Var1 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 14L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 15L, 16L, 1L, 2L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 15L, 16L, 11L), .Label = c("PVC1", "PVC2", "PVC3", "PVC4",
"PVC5", "PVC6", "PVC7", "PVC8", "PVC9", "PVC10", "PVC11", "PVC12",
"PVC13", "PVC14", "PVC15", "PVC16"), class = "factor"), Var2 = c(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, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L
), value = c(0.404444444, 0.436329588, 0.46031746, 0.479318735,
0.466230937, 0.480874317, 0.476811594, 0.441558442, 0.449172577,
0.476525822, 0.452674897, 0.460918332, 0.368041912, 0.339160839,
0.415355269, 0.408163265, 0.401826484, 0.45411985, 0.468609865,
0.479735318, 0.464052288, 0.469945355, 0.476811594, 0.444032158,
0.453900709, 0.494004796, 0.467315716, 0.457805907, 0.387071651,
0.390737117, 0.408679065, 0.425170068, 0.355555556, 0.438069217,
0.423076923, 0.466666667, 0.450980392, 0.422222222, 0.469298246,
0.43196005, 0.416666667, 0.496402878, 0.428676201, 0.382113821,
0.349765258, 0.332280147, 0.373371925, 0.346448087, 0.415555556,
0.440508629, 0.435222672, 0.455833333, 0.446623094, 0.422222222,
0.463450292, 0.43258427, 0.425675676, 0.497584541, 0.422524565,
0.392592593, 0.362779741, 0.337552743, 0.379856115, 0.348888889,
0.391111111, 0.421004566, 0.426439232, 0.480367586, 0.472766885,
0.455555556, 0.495726496, 0.447565543, 0.424460432, 0.48441247,
0.435164835, 0.39600551, 0.3858393, 0.323655914, 0.383693046,
0.329988852, 0.395555556, 0.452380952, 0.454756381, 0.448129252,
0.496732026, 0.423728814, 0.502923977, 0.433832709, 0.41607565,
0.498800959, 0.399161736, 0.368421053, 0.386568387, 0.369901547,
0.398550725, 0.34006734, 0.406392694, 0.455840456, 0.458598726,
0.43792517, 0.501089325, 0.427777778, 0.49122807, 0.435081149,
0.416020672, 0.48441247, 0.40617284, 0.379298942, 0.402298851,
0.361462729, 0.396135266, 0.356666667, 0.353333333, 0.439182916,
0.469316597, 0.461868038, 0.490196078, 0.405555556, 0.505847953,
0.430529595, 0.406619385, 0.470023981, 0.395262768, 0.355072464,
0.373677249, 0.348008386, 0.382804995, 0.355481728, 0.415555556,
0.481481481, 0.4550036, 0.485074627, 0.501089325, 0.5, 0.51754386,
0.465043695, 0.438478747, 0.501199041, 0.457733481, 0.416815742,
0.360672976, 0.388285024, 0.397509579, 0.356589147, 0.384444444,
0.482917821, 0.452525253, 0.487864078, 0.501089325, 0.488888889,
0.513157895, 0.47627965, 0.475609756, 0.513189448, 0.471391657,
0.419797257, 0.38467433, 0.376081425, 0.396666667, 0.370985604,
0.42, 0.477777778, 0.436063218, 0.476782753, 0.490196078, 0.466666667,
0.51754386, 0.45505618, 0.44295302, 0.532374101, 0.460707635,
0.426019548, 0.35755814, 0.389842632, 0.388489209, 0.358730159,
0.422222222, 0.459610028, 0.473304473, 0.502487562, 0.509803922,
0.438888889, 0.516081871, 0.480024969, 0.457317073, 0.527577938,
0.460969293, 0.424148607, 0.386850153, 0.369161868, 0.397677794,
0.357696567, 0.433333333, 0.450704225, 0.429118774, 0.497031383,
0.505446623, 0.455555556, 0.492690058, 0.444444444, 0.409722222,
0.501199041, 0.444812362, 0.414860681, 0.361111111, 0.390096618,
0.394724221, 0.358803987, 0.426666667, 0.471837488, 0.495748299,
0.511982571, 0.45, 0.513157895, 0.465043695, 0.438478747, 0.498800959,
0.453200148, 0.409375, 0.329166667, 0.384172662, 0.38961039,
0.413333333, 0.406113537, 0.450728363, 0.435244161, 0.431693989,
0.441520468, 0.427745665, 0.378076063, 0.389671362, 0.427222222,
0.397905759, 0.423295455, 0.375268817, 0.391111111, 0.39893617,
0.461538462, 0.437367304, 0.448087432, 0.454678363, 0.421323057,
0.384787472, 0.394366197, 0.419141914, 0.401331931, 0.423768939,
0.368817204, 0.42680776)), .Names = c("Var1", "Var2", "value"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L,
157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L,
168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L,
179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L,
190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L,
201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 212L,
213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 222L, 223L, 224L,
225L, 226L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L,
239L, 240L, 241L, 242L, 244L, 245L, 246L, 247L, 248L, 249L, 250L,
251L, 252L, 255L, 256L, 267L), class = "data.frame")
I'm not exactly sure how I solved this. I can only assume I was making a really stupid mistake before, but here's the code that finally produced the desired outcome:
bp_gc <- ggplot(melted_data, aes(x=Var1, y=value*100)) + theme_bw()
bp_gc <- bp_gc + geom_rect(xmin=0, xmax=17,
ymin=(operon_gc-opgc_stdev)*100,
ymax=(operon_gc+opgc_stdev)*100,
fill = "grey79", alpha=0.05)
bp_gc <- bp_gc + geom_rect(xmin=0, xmax=17,
ymin=(genome_gc-gengc_stdev)*100,
ymax=(genome_gc+gengc_stdev)*100,
fill = "beige", alpha=.08)
bp_gc <- bp_gc + geom_abline(intercept=genome_gc*100, slope=0,
colour="gray14", linetype=3)
bp_gc <- bp_gc + geom_abline(intercept=operon_gc*100, slope=0,
colour="gray14", linetype=3)
bp_gc <- bp_gc + geom_boxplot(alpha = 0.7, fill="dodgerblue", color="gray11")
bp_gc <- bp_gc + ylab("GC Content (%)")
bp_gc <- bp_gc + xlab("Locus")
bp_gc <- bp_gc + theme(legend.position = "none",
axis.text.x = element_text(angle=45, hjust=1))
bp_gc <- bp_gc + coord_cartesian(ylim=c(30,60))
bp_gc <- bp_gc + geom_path(data=func_data, linetype=4, size=0.9, aes(x=x,y=y*100))
bp_gc
I'm not 100% clear on what you're trying to achieve. Is it like this?
ggplot(melted_df, aes(Var1, value)) +
geom_boxplot()
ggplot(df, aes(Var1, value)) +
stat_summary(fun.y = median, geom = "path", aes(group = 1)) +
geom_boxplot()
If you really want to compute your statistics outside the main dataframe, it's usually best to do it something like this:
ggplot(df1, aes(x, y)) + geom_point() +
geom_path(data = summarydf, aes(xmean, ymean))

Predict values for each group in gamm4

I have a data set like this:
dat <- structure(list(Y = c(152.75, 167.7, 169.7, 173.2, 174.4, 177.1,
196, 200.45, 206.1, 206.65, 203, 186.65, 208.9, 192.95, 201.05,
203.45, 200.3, 197.55, 205.1, 198.1, 205.15, 189.35, 201.25,
194.55, 204.15, 200.95, 166.6, 165.1, 175.2, 168.4, 153, 168.4,
161, 170.1, 168.15, 167.3, 169.2, 169.25, 185.35, 185.9, 178.55,
193.2, 210.25, 203.75, 203.25, 203.7, 200.15, 204, 204, 206.3,
197.7, 190.5, 185.95, 199, 185.1, 194.35, 186.2, 190.95, 191.55,
177.8, 182.95, 186.3, 177.25, 186.35, 177.1, 183.9, 188.55, 184.05,
188.55, 187.25, 185.25, 174.8, 180.9, 171.4, 169.6, 176.7, 178.35,
191.3, 180.45, 187.5, 183.85, 187.7, 176.45, 188.7, 179.15, 183.25,
180.1, 184.35, 185.35, 184.25, 182.55, 185.15, 181.2, 184.6,
183.05, 182.35, 177.55, 179.85, 176.1, 175.9, 173.7, 180.7, 194.55,
190.3, 200.5, 193.05, 191.55, 190.65, 194.9, 192.8, 202.65, 200.35,
181.95, 194.85, 198.3, 199.7, 185.7, 195.9, 195.15, 191.85, 198.65,
188.9, 192.25, 197.8, 185.75, 193.5, 178.2, 170.15, 175.4, 176.25,
176.6, 179.8, 182, 173.35, 181.75, 188.05, 198.05, 204.75, 190.75,
196.15, 193.15, 195.4, 192.35, 165.55, 187.15, 191.35, 200.4,
200.4, 204.85, 211.3, 206.45, 205.95, 201, 198.6, 202.45, 192.95,
198.25, 190.85, 182.9, 184.5, 175.75, 174.95, 178.8, 173.2, 174,
176.75, 167.2, 161.1, 155.6, 178.6, 187.8, 194.05), X1 = c(4L,
6L, 7L, 8L, 9L, 10L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 12L, 13L, 14L, 15L, 4L, 5L, 6L, 7L, 8L, 4L, 5L,
6L, 7L, 11L, 14L, 15L, 16L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 4L, 5L, 9L, 13L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L, 4L, 5L, 7L, 8L, 9L, 10L, 11L, 12L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 4L, 5L, 8L, 9L, 10L, 11L, 4L, 5L, 6L, 7L, 8L,
10L, 11L, 12L, 13L, 4L, 6L, 7L, 8L, 9L, 12L, 13L, 14L, 15L, 16L,
17L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 12L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 4L, 6L, 7L, 4L, 5L, 7L, 9L, 11L, 12L, 15L, 16L, 17L,
20L, 21L, 22L, 4L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 16L,
18L, 4L, 5L, 6L), X2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 18L, 18L, 18L), .Label = c("bec", "bi", "ebk", "ele",
"eli", "ian", "isy", "ith", "lda", "lli", "na", "nja", "ra",
"rda", "ria", "rik", "tje", "tri"), class = "factor")), .Names = c("Y",
"X1", "X2"), row.names = c(142L, 143L, 144L, 145L, 146L, 147L,
87L, 88L, 89L, 90L, 91L, 92L, 93L, 160L, 161L, 162L, 163L, 164L,
165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 82L, 83L, 84L, 85L, 86L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 74L, 75L, 76L, 77L, 78L, 79L, 80L,
81L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L,
112L, 113L, 114L, 115L, 116L, 117L, 118L, 133L, 134L, 135L, 136L,
137L, 138L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 119L,
120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 66L,
67L, 68L, 69L, 70L, 71L, 72L, 73L, 94L, 95L, 96L, 97L, 98L, 99L,
100L, 101L, 130L, 131L, 132L, 148L, 149L, 150L, 151L, 152L, 153L,
154L, 155L, 156L, 157L, 158L, 159L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 139L, 140L, 141L), class = "data.frame")
and I applied a gamm4-model from gamm4-package on it:
library(gamm4)
gamm.1 <- gamm4(Y ~ s(X1),random = ~(1+X1|X2),data = dat)
I also predicted and plotted the smoothed values using:
newDat <- data.frame(X1 = min(dat$X1):max(dat$X1))
p0 <- predict(gamm.1$gam,newDat,se=T)
plot(dat$X1,dat$Y)
lines(newDat$X1,p0$fit,lwd=3)
My question is: how can I predict the smoothed lines for each of the groups (X2)?
I know that I can get the random effects via ranef(gamm.1$mer) but I don't know how to use them correctly.

Box -Plot for Groups in R

I am having trouble to make a box-plot for differet groups side by side.
dput(df)
structure(list(UserName = structure(c(20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 3L, 1L, 1L, 3L, 3L, 26L, 3L, 29L, 2L, 29L, 7L,
10L, 2L, 10L, 10L, 6L, 30L, 2L, 2L, 1L, 1L, 3L, 16L, 10L, 10L,
6L, 10L, 2L, 6L, 29L, 6L, 1L, 4L, 17L, 5L, 5L, 5L, 5L, 14L, 5L,
14L, 5L, 24L, 23L, 23L, 28L, 25L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 31L, 31L,
4L, 27L, 27L, 27L, 12L, 12L, 12L, 12L, 19L, 19L, 22L, 12L, 11L,
11L, 11L, 9L, 22L, 12L, 15L, 22L, 22L, 22L, 11L, 9L, 11L, 12L,
11L, 18L, 18L, 22L, 22L, 18L, 18L, 19L, 22L, 22L, 19L, 19L, 22L,
19L, 11L, 19L, 15L, 22L, 19L, 19L, 9L, 19L, 19L, 9L, 18L, 12L,
18L, 22L, 8L, 13L, 13L, 13L), .Label = c("CYL", "FAL1",
"GS", "HA1", "HX", "HURRT", "KWY", "LEI", "L1",
"LIGYR", "LYC", "LJ", "LQI", "LIC", "LOK", "MDA",
"NMZ", "NGK", "OXJ", "P_PT", "P_SH", "PDI",
"PONN", "PEHMB", "TGT1", "TNS", "THOLH", "TOT",
"WAN1", "WAK", "YH"), class = "factor"), Division = 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, 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, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 2L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L), .Label = c("BATCH",
"BTR", "IIT", "POL", "PTC", "PTP", "PTQ", "SPL", "TM"), class = "factor"),
SpoolUsage_max = structure(c(20L, 21L, 22L, 25L, 26L, 27L,
29L, 33L, 34L, 39L, 41L, 43L, 47L, 48L, 49L, 51L, 52L, 53L,
55L, 57L, 58L, 59L, 60L, 61L, 81L, 82L, 83L, 87L, 99L, 102L,
108L, 108L, 141L, 143L, 155L, 158L, 160L, 5L, 8L, 90L, 94L,
96L, 98L, 104L, 110L, 111L, 112L, 113L, 114L, 116L, 117L,
118L, 120L, 122L, 124L, 126L, 127L, 128L, 129L, 130L, 131L,
132L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 142L, 144L,
145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L,
156L, 157L, 199L, 201L, 203L, 204L, 205L, 206L, 69L, 70L,
71L, 72L, 73L, 74L, 75L, 77L, 78L, 80L, 9L, 16L, 16L, 17L,
23L, 36L, 42L, 46L, 46L, 46L, 50L, 56L, 63L, 65L, 89L, 97L,
101L, 125L, 172L, 174L, 174L, 184L, 185L, 186L, 191L, 196L,
207L, 4L, 6L, 68L, 106L, 107L, 35L, 10L, 37L, 95L, 175L,
175L, 188L, 189L, 198L, 3L, 24L, 91L, 92L, 40L, 40L, 44L,
45L, 103L, 133L, 178L, 194L, 195L, 200L, 7L, 66L, 164L, 165L,
166L, 167L, 168L, 169L, 170L, 13L, 14L, 35L, 100L, 119L,
123L, 18L, 54L, 109L, 79L, 9L, 11L, 15L, 18L, 19L, 30L, 31L,
32L, 38L, 54L, 62L, 64L, 84L, 85L, 86L, 88L, 93L, 109L, 115L,
121L, 159L, 161L, 161L, 162L, 162L, 173L, 176L, 177L, 179L,
180L, 181L, 182L, 183L, 187L, 190L, 192L, 193L, 202L, 208L,
1L, 2L, 67L, 76L, 79L, 105L, 163L, 171L, 12L, 28L, 197L), .Label = c("1,002.12",
"1,027.99", "1,207.40", "1,368.90", "1,599.16", "1,616.11",
"1,804.20", "1,804.28", "106.09", "106.49", "106.5", "110.59",
"118.37", "119.12", "122.69", "123.19", "123.3", "123.49",
"125.19", "126.54", "128.72", "128.94", "132.43", "132.51",
"132.55", "135.45", "137.26", "141.87", "142.59", "145.93",
"146.11", "146.52", "147.22", "149.04", "149.27", "151.42",
"154.7", "155.61", "155.9", "156.07", "156.23", "157.8",
"158.92", "159.41", "160.22", "162.84", "163.45", "166.11",
"166.63", "170.96", "171.19", "172.73", "173.24", "176.51",
"176.56", "176.94", "177.75", "181.23", "184.5", "190.34",
"190.7", "193.7", "197.78", "199.66", "199.95", "2,007.44",
"2,009.54", "2,030.52", "2,273.26", "2,440.88", "2,473.26",
"2,633.03", "2,663.28", "2,706.98", "2,723.36", "2,755.44",
"2,759.55", "2,821.46", "2,829.16", "2,835.27", "200.27",
"204.97", "206.63", "208.96", "212.89", "216.38", "217.45",
"232.67", "234.05", "251.6", "253.61", "258.98", "262.16",
"266.48", "266.88", "268.92", "271.27", "276.31", "279.41",
"283.22", "289.51", "292.47", "292.67", "298.71", "3,003.51",
"3,184.47", "3,885.86", "305.69", "307.59", "308.38", "309.54",
"310.48", "313.8", "313.91", "314.72", "317.51", "319.85",
"321.54", "321.57", "321.63", "322.46", "327.56", "328.57",
"331.06", "331.85", "333.85", "333.9", "333.98", "334.28",
"335.22", "335.89", "336.63", "337.3", "337.74", "339.74",
"341.78", "345.12", "345.54", "347.99", "348", "348.13",
"348.48", "348.49", "349.3", "350.18", "350.53", "353.08",
"353.74", "353.98", "354.59", "355.55", "358.47", "359.14",
"359.59", "359.98", "361.84", "362.86", "370.08", "373.83",
"376.4", "394.45", "395.48", "4,166.39", "4,667.87", "4,696.73",
"4,708.79", "4,729.34", "4,731.65", "4,757.80", "4,760.75",
"4,769.30", "415.37", "421.52", "423.58", "428.34", "487.35",
"491.12", "495.1", "495.91", "495.94", "499.07", "517.68",
"527.29", "536.62", "550.83", "572.71", "574.75", "576.42",
"605.69", "613.56", "632.1", "668.87", "669.68", "686.88",
"688.05", "762.93", "770.16", "781.07", "858.09", "858.68",
"864.56", "868.03", "874.65", "879.09", "886.68", "890.64",
"911.58", "954.76"), class = "factor")), .Names = c("UserName",
"Division", "SpoolUsage_max"), class = "data.frame", row.names = c(NA,
-223L))
I am trying to get a box-plot for each Division (each division withits own users) side by side.
I have tried the following:
library(reshape2)
library(ggplot2)
p <- ggplot(melt(df), aes(variable, value)) + geom_boxplot()
p <- p + geom_boxplot(fill = "grey80", colour = "#3366FF")
p <- p +xlab("UserName")+ylab("SpoolUsage_Max")+ggtitle("Spool Usage Analysis by Users")
p <- p +coord_flip()
p
I cannot produce with division (with its users ) each divison with a color for a side by side single box plot
Here you go:
df <- df %>% mutate(val = gsub(",", "", SpoolUsage_max) %>% as.numeric)
ggplot(df, aes(Division, val, fill=UserName)) + geom_boxplot()
May be neater if you use facet_wrap option.

How to work out the Net Promotion Score by prop.table()

############ uncoded data
x10<- structure(c(0L, 0L, 0L, 0L, 1L, 1L, 1L, 5L, 8L, 9L, 31L, 1L,
0L, 0L, 0L, 1L, 0L, 1L, 2L, 7L, 2L, 10L, 0L, 2L, 0L, 2L, 2L,
5L, 2L, 4L, 6L, 8L, 4L, 1L, 1L, 3L, 2L, 2L, 6L, 1L, 12L, 18L,
7L, 29L, 8L, 4L, 6L, 8L, 6L, 19L, 3L, 9L, 12L, 3L, 12L, 14L,
1L, 2L, 1L, 3L, 1L, 0L, 4L, 6L, 3L, 11L, 0L, 0L, 0L, 1L, 3L,
7L, 5L, 8L, 21L, 26L, 51L, 0L, 1L, 0L, 3L, 5L, 10L, 9L, 29L,
55L, 60L, 125L, 3L, 0L, 1L, 1L, 3L, 10L, 1L, 6L, 18L, 17L, 13L,
6L, 3L, 4L, 13L, 6L, 33L, 17L, 48L, 84L, 54L, 103L, 34L, 11L,
20L, 27L, 26L, 50L, 29L, 30L, 54L, 28L, 34L, 31L, 5L, 7L, 3L,
4L, 20L, 8L, 16L, 16L, 8L, 41L, 1L, 0L, 0L, 3L, 1L, 3L, 3L, 11L,
19L, 16L, 56L, 0L, 0L, 0L, 0L, 3L, 11L, 3L, 18L, 25L, 21L, 62L,
3L, 0L, 1L, 4L, 2L, 7L, 8L, 15L, 22L, 12L, 19L, 5L, 2L, 8L, 9L,
9L, 42L, 18L, 51L, 70L, 45L, 103L, 29L, 15L, 23L, 34L, 25L, 57L,
23L, 38L, 55L, 30L, 33L, 36L, 5L, 5L, 6L, 6L, 16L, 6L, 10L, 17L,
9L, 35L, 2L, 0L, 1L, 1L, 2L, 4L, 6L, 8L, 22L, 33L, 73L, 0L, 0L,
0L, 1L, 2L, 7L, 7L, 15L, 27L, 21L, 56L, 1L, 2L, 2L, 0L, 2L, 9L,
4L, 8L, 24L, 13L, 17L, 14L, 2L, 8L, 10L, 16L, 51L, 16L, 51L,
69L, 29L, 99L, 44L, 18L, 25L, 34L, 19L, 49L, 26L, 43L, 63L, 15L,
30L, 42L, 9L, 17L, 7L, 3L, 16L, 8L, 13L, 22L, 18L, 45L, 0L, 0L,
1L, 3L, 0L, 7L, 4L, 14L, 15L, 20L, 47L, 0L, 1L, 0L, 1L, 1L, 3L,
3L, 5L, 6L, 11L, 21L, 1L, 0L, 0L, 4L, 2L, 3L, 8L, 7L, 17L, 3L,
13L, 5L, 2L, 6L, 13L, 15L, 34L, 19L, 42L, 62L, 37L, 83L, 52L,
16L, 26L, 26L, 29L, 53L, 28L, 45L, 45L, 15L, 22L, 26L, 8L, 12L,
11L, 5L, 12L, 5L, 7L, 17L, 10L, 28L), .Dim = c(11L, 6L, 5L), .Dimnames = structure(list(
c("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"),
c("I've changed for work/ a new job/ gone on a work plan",
"I want a phone that doesn't offer", "I want Best Mates/ Favourites",
"I was offered or saw a better offer on another network",
"Issues with the network (poor coverage)", "Other"
), YearQuarter = c("2011-09-01", "2011-12-01", "2012-03-01",
"2012-06-01", "2012-09-01")), .Names = c("", "", "YearQuarter"
)), class = "table")
############ recoded data
x10 <- structure(c(40L, 3L, 13L, 12L, 3L, 9L, 12L, 13L, 10L, 36L, 16L,
30L, 15L, 54L, 21L, 14L, 22L, 10L, 77L, 16L, 29L, 185L, 28L,
84L, 30L, 19L, 24L, 157L, 82L, 132L, 62L, 197L, 84L, 49L, 78L,
32L, 72L, 11L, 30L, 83L, 17L, 43L, 31L, 25L, 37L, 148L, 93L,
121L, 63L, 206L, 93L, 44L, 80L, 27L, 106L, 16L, 30L, 77L, 17L,
42L, 30L, 20L, 32L, 128L, 117L, 120L, 45L, 215L, 106L, 63L, 102L,
35L, 67L, 15L, 29L, 32L, 9L, 11L, 16L, 18L, 24L, 120L, 94L, 104L,
37L, 230L, 90L, 38L, 79L, 24L), .Dim = c(3L, 6L, 5L), .Dimnames = structure(list(
c("Promoters", "Detractors", "Passive"), c("I've changed for work/ a new job/ gone on a work plan",
"I want a phone that doesn't offer", "I want Best Mates/ Favourites",
"I was offered or saw a better offer on another network",
"Issues with the network (poor coverage)", "Other"
), YearQuarter = c("2011-09-01", "2011-12-01", "2012-03-01",
"2012-06-01", "2012-09-01")), .Names = c("", "", "YearQuarter"
)), class = "table")
x10.p <- round(prop.table(x10,c(3,2)),2)*100
Hi there
The Net Promotion Score is a question which asks the consumers to rate the 'the likelihood to recommend the product or the service' on a zero to ten scale. People reported with 10 and 9 are called 'promoters', people rated 8 and 7 are seen as 'Passive', and people reported less than 6 are considered as detractors. The Net Promotion score is the difference between the percentage of 'Promoters' minus the the percentage of 'Detractors'.
I summerised and recoded the answers from the question into a table x10 from Sep 2011 to Sep 2012. The numbers are actual people counts for each group (Promoter,Detractor and Passive). Apologies for the three dimensioanl table, I am interested in the Net Promoter Score for each reason( i.e what's the percentage difference among the promoters and detractors for "I've changed for work/ a new job/ gone on a work plan" in Sep 2012.
The Net Promotion Score before I can plot it which requires a bit manipulation. I wonder if anyone knows to how do it?
Cheers
First, don't round until you've done all your calculations (otherwise you will have percentages not adding to 1)
x10.p <- prop.table(x10,c(3,2))*100
# get the total promoters
promoters <- apply(x10.p, 2:3, function(x) sum(tail(x,2)))
# and detractors
detractors <- apply(x10.p, 2:3, function(x) sum(head(x,7)))
# passive is everything else
passive <- passive <- 100 - (detractors +promoters)
# the net score
net <- promoters - detractors
net
YearQuarter
2011-09-01 2011-12-01 2012-03-01 2012-06-01 2012-09-01
I've changed for work/ a new job/ gone on a work plan 66.071429 50.00000 53.982301 59.210526 46.846847
I want a phone that doesn't offer 37.500000 52.86195 46.153846 44.117647 44.230769
I want Best Mates/ Favourites -2.857143 15.06849 6.451613 12.195122 -3.448276
I was offered or saw a better offer on another network 24.390244 20.21563 15.193370 3.013699 8.176101
Issues with the network (poor coverage) -43.333333 -39.35860 -39.502762 -46.448087 -54.061625
Other -17.391304 -18.23899 -23.841060 -19.500000 -29.078014
You want september 2012, select just that column, with drop = FALSE to ensure it is still a matrix with 1 column.
net[,'2012-09-01', drop = FALSE]
YearQuarter
2012-09-01
I've changed for work/ a new job/ gone on a work plan 46.846847
I want a phone that doesn't offer 44.230769
I want Best Mates/ Favourites -3.448276
I was offered or saw a better offer on another network 8.176101
Issues with the network (poor coverage) -54.061625
Other -29.078014

Resources