Home > Software design >  Unable to plot grouped_ggbetweenstats
Unable to plot grouped_ggbetweenstats

Time:07-02

I am trying to plot a grouped ggstatsplot graph and I received an error group length is 0 but data length > 0. I am trying to see whats the stats for the different dates groupedby the household size of the dataset. The Y axis was supposed to be the visit count. May I know where is the error of my code? Or am I doing the groupby wrongly?

grouped_ggbetweenstats(
  data = recreation_visit_social_2,
  x = Dates,
  y = Visitcount,
  grouping.var = `Household Size`,
  ylab = "VisitCount",
  pairwise.comparisons = FALSE,
  ggtheme = ggplot2::theme_classic()   theme(axis.title.y= element_text(angle=0),
                                             plot.title = element_text(size = 14, face = "bold", hjust=0.5)),
  ggplot.component = ggplot2::scale_color_manual(values = color_palettes),
  annotation.args  = list(title = paste0("Visit Count of Pubs by ", Dates))
)

dput of recreation_visit

dput(recreation_visit_social_2)
structure(list(`Pub Id` = c("1342", "1342", "1342", "1342", "1342", 
"1342", "1342", "1342", "1342", "1342", "1342", "1342", "1342", 
"1342", "1342", "1342", "1342", "1342", "1342", "1342", "1342", 
"1342", "1342", "1342", "1342", "1342", "1342", "1342", "1342", 
"1342", "1343", "1343", "1343", "1343", "1343", "1343", "1343", 
"1343", "1343", "1343", "1343", "1343", "1343", "1343", "1343", 
"1343", "1343", "1343", "1343", "1343", "1343", "1343", "1343", 
"1343", "1343", "1343", "1343", "1343", "1343", "1343", "1344", 
"1344", "1344", "1344", "1344", "1344", "1344", "1344", "1344", 
"1344", "1344", "1344", "1344", "1344", "1344", "1344", "1344", 
"1344", "1344", "1344", "1344", "1344", "1344", "1344", "1344", 
"1344", "1344", "1344", "1344", "1344", "1798", "1798", "1798", 
"1798", "1798", "1798", "1798", "1798", "1798", "1798", "1798", 
"1798", "1798", "1798", "1798", "1798", "1798", "1798", "1798", 
"1798", "1798", "1798", "1798", "1798", "1798", "1798", "1798", 
"1798", "1798", "1798", "1799", "1799", "1799", "1799", "1799", 
"1799", "1799", "1799", "1799", "1799", "1799", "1799", "1799", 
"1799", "1799", "1799", "1799", "1799", "1799", "1799", "1799", 
"1799", "1799", "1799", "1799", "1799", "1799", "1799", "1799", 
"1799", "1800", "1800", "1800", "1800", "1800", "1800", "1800", 
"1800", "1800", "1800", "1800", "1800", "1800", "1800", "1800", 
"1800", "1800", "1800", "1800", "1800", "1800", "1800", "1800", 
"1800", "1800", "1800", "1800", "1800", "1800", "1800", "442", 
"442", "442", "442", "442", "442", "442", "442", "442", "442", 
"442", "442", "442", "442", "442", "442", "442", "442", "442", 
"442", "442", "442", "442", "442", "442", "442", "442", "442", 
"442", "442", "443", "443", "443", "443", "443", "443", "443", 
"443", "443", "443", "443", "443", "443", "443", "443", "443", 
"443", "443", "443", "443", "443", "443", "443", "443", "443", 
"443", "443", "443", "443", "443", "444", "444", "444", "444", 
"444", "444", "444", "444", "444", "444", "444", "444", "444", 
"444", "444", "444", "444", "444", "444", "444", "444", "444", 
"444", "444", "444", "444", "444", "444", "444", "444", "892", 
"892", "892", "892", "892", "892", "892", "892", "892", "892", 
"892", "892", "892", "892", "892", "892", "892", "892", "892", 
"892", "892", "892", "892", "892", "892", "892", "892", "892", 
"892", "892", "893", "893", "893", "893", "893", "893", "893", 
"893", "893", "893", "893", "893", "893", "893", "893", "893", 
"893", "893", "893", "893", "893", "893", "893", "893", "893", 
"893", "893", "893", "893", "893", "894", "894", "894", "894", 
"894", "894", "894", "894", "894", "894", "894", "894", "894", 
"894", "894", "894", "894", "894", "894", "894", "894", "894", 
"894", "894", "894", "894", "894", "894", "894", "894"), Dates = 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, 
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, 1L, 1L, 2L, 2L,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, 9L, 
9L, 10L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 
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), levels = c("Mar 2022", "Apr 2022", "May 2022", "Jun 2022", 
"Jul 2022", "Aug 2022", "Sep 2022", "Oct 2022", "Nov 2022", "Dec 2022", 
"Jan 2023", "Feb 2023", "Mar 2023", "Apr 2023", "May 2023"), class = "factor"), 
    `Household Size` = c("1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", "1", "2", 
    "1", "2", "1", "2"), Visitcount = c(1783L, 2021L, 1028L, 
    1302L, 945L, 1089L, 835L, 1064L, 872L, 1097L, 803L, 941L, 
    797L, 1043L, 846L, 1086L, 753L, 977L, 903L, 975L, 906L, 1076L, 
    706L, 867L, 841L, 986L, 824L, 977L, 642L, 710L, 1476L, 1373L, 
    822L, 782L, 740L, 676L, 633L, 696L, 650L, 632L, 640L, 599L, 
    612L, 559L, 648L, 674L, 578L, 575L, 623L, 635L, 619L, 630L, 
    519L, 507L, 565L, 615L, 620L, 642L, 487L, 436L, 2407L, 2243L, 
    1317L, 1355L, 1071L, 1184L, 1039L, 1138L, 1076L, 1216L, 994L, 
    1142L, 952L, 1122L, 1066L, 1240L, 925L, 1072L, 1004L, 1160L, 
    1022L, 1195L, 904L, 1067L, 1004L, 1165L, 1082L, 1168L, 726L, 
    803L, 1205L, 1160L, 712L, 749L, 663L, 660L, 598L, 576L, 635L, 
    645L, 571L, 565L, 580L, 635L, 626L, 651L, 541L, 512L, 568L, 
    580L, 570L, 584L, 505L, 533L, 518L, 597L, 500L, 576L, 444L, 
    413L, 1357L, 1208L, 828L, 746L, 651L, 676L, 652L, 564L, 667L, 
    669L, 592L, 614L, 588L, 526L, 706L, 590L, 654L, 523L, 633L, 
    558L, 638L, 557L, 561L, 467L, 614L, 508L, 648L, 544L, 437L, 
    401L, 1245L, 1332L, 787L, 882L, 671L, 725L, 578L, 659L, 588L, 
    740L, 556L, 696L, 613L, 611L, 616L, 714L, 502L, 586L, 596L, 
    661L, 598L, 643L, 526L, 588L, 539L, 607L, 560L, 680L, 427L, 
    498L, 906L, 850L, 514L, 501L, 385L, 432L, 371L, 394L, 395L, 
    421L, 420L, 410L, 383L, 436L, 402L, 487L, 354L, 431L, 401L, 
    455L, 396L, 439L, 337L, 390L, 352L, 406L, 377L, 422L, 275L, 
    292L, 978L, 887L, 479L, 536L, 403L, 447L, 385L, 402L, 429L, 
    389L, 414L, 410L, 401L, 397L, 404L, 483L, 360L, 366L, 421L, 
    400L, 406L, 413L, 360L, 357L, 370L, 391L, 385L, 413L, 300L, 
    281L, 537L, 666L, 313L, 472L, 315L, 409L, 296L, 363L, 285L, 
    380L, 278L, 362L, 266L, 356L, 302L, 411L, 259L, 301L, 308L, 
    385L, 288L, 374L, 253L, 343L, 291L, 342L, 272L, 345L, 227L, 
    256L, 1089L, 1131L, 608L, 604L, 481L, 570L, 481L, 538L, 474L, 
    509L, 431L, 492L, 438L, 450L, 481L, 519L, 409L, 482L, 450L, 
    455L, 448L, 494L, 413L, 447L, 410L, 488L, 489L, 510L, 333L, 
    413L, 999L, 983L, 508L, 598L, 486L, 554L, 435L, 511L, 434L, 
    552L, 456L, 556L, 406L, 503L, 417L, 499L, 399L, 492L, 438L, 
    503L, 416L, 498L, 356L, 413L, 387L, 452L, 448L, 483L, 299L, 
    411L, 903L, 902L, 492L, 460L, 420L, 420L, 422L, 351L, 407L, 
    359L, 410L, 315L, 402L, 310L, 425L, 359L, 409L, 311L, 443L, 
    350L, 378L, 342L, 353L, 291L, 402L, 281L, 440L, 383L, 288L, 
    240L)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -360L), groups = structure(list(`Pub Id` = c("1342", 
"1342", "1342", "1342", "1342", "1342", "1342", "1342", "1342", 
"1342", "1342", "1342", "1342", "1342", "1342", "1343", "1343", 
"1343", "1343", "1343", "1343", "1343", "1343", "1343", "1343", 
"1343", "1343", "1343", "1343", "1343", "1344", "1344", "1344", 
"1344", "1344", "1344", "1344", "1344", "1344", "1344", "1344", 
"1344", "1344", "1344", "1344", "1798", "1798", "1798", "1798", 
"1798", "1798", "1798", "1798", "1798", "1798", "1798", "1798", 
"1798", "1798", "1798", "1799", "1799", "1799", "1799", "1799", 
"1799", "1799", "1799", "1799", "1799", "1799", "1799", "1799", 
"1799", "1799", "1800", "1800", "1800", "1800", "1800", "1800", 
"1800", "1800", "1800", "1800", "1800", "1800", "1800", "1800", 
"1800", "442", "442", "442", "442", "442", "442", "442", "442", 
"442", "442", "442", "442", "442", "442", "442", "443", "443", 
"443", "443", "443", "443", "443", "443", "443", "443", "443", 
"443", "443", "443", "443", "444", "444", "444", "444", "444", 
"444", "444", "444", "444", "444", "444", "444", "444", "444", 
"444", "892", "892", "892", "892", "892", "892", "892", "892", 
"892", "892", "892", "892", "892", "892", "892", "893", "893", 
"893", "893", "893", "893", "893", "893", "893", "893", "893", 
"893", "893", "893", "893", "894", "894", "894", "894", "894", 
"894", "894", "894", "894", "894", "894", "894", "894", "894", 
"894"), Dates = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 3L, 
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
15L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
14L, 15L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
13L, 14L, 15L), levels = c("Mar 2022", "Apr 2022", "May 2022", 
"Jun 2022", "Jul 2022", "Aug 2022", "Sep 2022", "Oct 2022", "Nov 2022", 
"Dec 2022", "Jan 2023", "Feb 2023", "Mar 2023", "Apr 2023", "May 2023"
), 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, 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), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), row.names = c(NA, -180L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE))


CodePudding user response:

This looks like a bug (FYI: I just filed an enter image description here

CodePudding user response:

R is case sensitive so you should name your columns first differently. Also the number of labels is greater than default palette color count, so I used the default colorpalette from the ggsci package:

names(recreation_visit_social_2) <- c("Pub_Id", "Dates", "Household_Size", "Visitcount")

library(dplyr)
library(ggstatsplot)
recreation_visit_social_2 %>%
  grouped_ggbetweenstats(
  x = Dates,
  y = Visitcount,
  grouping.var = Household_Size,
  ylab = "VisitCount",
  pairwise.comparisons = FALSE,
  package = "ggsci",
  palette = "default_jco",
  ggtheme = ggplot2::theme_classic()   theme(axis.title.y= element_text(angle=0),
                                             plot.title = element_text(size = 14, face = "bold", hjust=0.5)),
  #ggplot.component = ggplot2::scale_color_manual(values = color_palettes),
  annotation.args  = list(title = paste0("Visit Count of Pubs by ", recreation_visit_social_2$Dates))
)

Output:

enter image description here

  • Related