Error: At least one layer must contain all faceting variables for dumbbell plot

I am getting this error message and I dont know what to do about it, I have tried to. use solutions from other posts yet to no avail.

Error: At least one layer must contain all faceting variables: Session, Trial_type.

  • Plot is missing Session, Trial_type
  • Layer 1 is missing Session
  • Layer 2 is missing Session
  • Layer 3 is missing Session
  • Layer 4 is missing Session
  • Layer 5 is missing Session, Trial_type
  • Layer 6 is missing Session
    In addition: Warning messages:
    1: In min(x) : no non-missing arguments to min; returning Inf
    2: In max(x) : no non-missing arguments to max; returning -Inf
    3: In min(x) : no non-missing arguments to min; returning Inf
    4: In max(x) : no non-missing arguments to max; returning -Inf
data10A <- structure(list(Session = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), conditon2 = structure(c(10L, 
4L, 12L, 6L, 11L, 5L, 1L, 7L, 3L, 9L, 2L, 8L, 10L, 4L, 12L, 6L, 
11L, 5L, 1L, 7L, 3L, 9L, 2L, 8L), .Label = c("CEN_LLL", "CTL_LLL", 
"IPS_LLL", "CEN_RRR", "CTL_RRR", "IPS_RRR", "CEN_RLR", "CTL_RLR", 
"IPS_RLR", "CEN_LRL", "CTL_LRL", "IPS_LRL"), class = "factor"), 
    Trial_type = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 
    1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 
    2L), .Label = c("Retention", "Transfer"), class = "factor"), 
    NormalizedJerk_102 = c(1270.168699, 2099.703957, 3259.268053, 
    1152.257445, 3810.890123, 4601.918336, 1792.371775, 1288.768888, 
    2699.08162, 1650.968794, 2018.457394, 6159.567785, 931.350429, 
    1053.84252, 1611.673955, 1034.363607, 5352.195367, 2499.83996, 
    1560.678962, 915.3845866, 1948.757464, 1341.815274, 2113.732859, 
    2051.140838), NormalizedJerk_104 = c(853.7034116, 924.8554548, 
    2268.966702, 675.7160839, 2442.874632, 1603.954653, 1010.111276, 
    794.1752256, 1313.813984, 1197.638788, 1039.577947, 3125.131019, 
    561.2311988, 767.7541159, 1019.744071, 769.6067294, 2232.404471, 
    1292.509181, 884.8343164, 663.0273865, 1230.369444, 717.8466364, 
    1536.027898, 1027.358586), key = c("Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk", "Change in normalized jerk", 
    "Change in normalized jerk")), row.names = c(NA, -24L), class = c("tbl_df", 
"tbl", "data.frame"))
 library(tidyverse)
 library(dumbbell)
library(ggplot)
 library(ggh4x)

dumbbell(data10A, id = "conditon2", key = "Trial_type", 
          leg = "Test", 
          column1 = "NormalizedJerk_102", 
          column2 = "NormalizedJerk_104", 
          delt = 1, lab1 = "Pre-test", lab2 = "Post-test", 
          p_col1 = "black", p_col2 = "grey40", 
          textsize = 4, segsize = 1.5, 
          pointsize = 2.5, 
          title = "Change in Normalized jerk from Pre- to Post-test")  + 
   facet_nested(. ~ Session + Trial_type, shrink=F ) +
   theme(axis.text.x = element_text(size = 12, face = "bold"),
         axis.text.y = element_text(size = 11, face = "bold"),
         legend.position = "top",
         legend.text = element_text(size = 12), 
         legend.title = element_text(size = 14),
         strip.text = element_text(face = "bold", size = 14, color = "black"))

I'm not familiar with the dumbbell package, and I'm not entirely sure what you want to achieve, but the error seems to come from the faceting. Specifically with the Session variable, maybe because the key you chose for the dumbbell function is only Trial_type. Or because not all trial types have all condition2.

Anyway, I've created a facet variable by pasting together the Session and Trial_type and used a simple facet_wrap on this. I kept the y-scale free to hide the condition2 that do not have data for a given set of Trial type.

#not pasting the initial data and library() calls.

data10A$facet <- paste(data10A$Trial_type, "- Session:", data10A$Session)

dumbbell(data10A, 
         id = "conditon2", 
         key = "facet", 
         leg = "Test", 
         column1 = "NormalizedJerk_102", 
         column2 = "NormalizedJerk_104", 
         delt = 1, lab1 = "Pre-test", lab2 = "Post-test", 
         p_col1 = "black", p_col2 = "grey40", 
         textsize = 4, segsize = 1.5, 
         pointsize = 2.5, 
         title = "Change in Normalized jerk from Pre- to Post-test")  +
  facet_wrap( ~ facet, scales = 'free_y') +
  # facet_nested(. ~ Trial_type, shrink=F ) +
  theme(axis.text.x = element_text(size = 12, face = "bold"),
        axis.text.y = element_text(size = 11, face = "bold"),
        legend.position = "top",
        legend.text = element_text(size = 12), 
        legend.title = element_text(size = 14),
        strip.text = element_text(face = "bold", size = 14, color = "black"))

Is that the sort of thing you wanted?

Yes please, thanks very much

I there a way to take off the y-tick labels off the right graph to allow spacing

If you remove the scales = 'free_y' argument from facet_wrap(), it will do so, but then you'll have many empty rows because the condition2 are not all present in all Trial_Type.

I'm not entirely sure why you want four panels, when you can display everything in only two by faceting by Session:

dumbbell(data10A, 
         id = "conditon2", 
         key = "Session", 
         leg = "Test", 
         column1 = "NormalizedJerk_102", 
         column2 = "NormalizedJerk_104", 
         delt = 1, lab1 = "Pre-test", lab2 = "Post-test", 
         p_col1 = "black", p_col2 = "grey40", 
         textsize = 4, segsize = 1.5, 
         pointsize = 2.5, 
         title = "Change in Normalized jerk from Pre- to Post-test")  +
  facet_wrap( ~ Session) +
  # facet_nested(. ~ Trial_type, shrink=F ) +
  theme(axis.text.x = element_text(size = 12, face = "bold"),
        axis.text.y = element_text(size = 11, face = "bold"),
        legend.position = "top",
        legend.text = element_text(size = 12), 
        legend.title = element_text(size = 14),
        strip.text = element_text(face = "bold", size = 14, color = "black"))

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.