-
Hi team, apologies if this is somewhere in the loads of helpful documentation and I overlooked the answer. Assume that I have a survey question that asks about gender identity. One of the options is "Prefer to self-describe" where then the user enters in text their description. When the data are collected, this open-ended response is stored as a separate variable. Is it possible to nest the levels (assume in this case there are only a few self-descriptions) of the open-ended response underneath the "Prefer to self-describe" level of the original question? The motivation here is to replicate visualizations previously completed in SAS at the request of a stakeholder. Please see the following dummy data and result/target outputs: Data:
Result:
Target output:
Note: This is not a real survey question. The example was contrived by ChatGPT to help illustrate my actual problem. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
this is what you are looking for: basic_table() |>
split_rows_by("Gender_Identity", label_pos = "visible") |>
summarize_row_groups(format = "xx") |>
analyze(vars = c("Self_Describe")) |>
analyze(vars = c("Age_Group", "Race"), nested = FALSE) |>
build_table(survey_data) %>%
trim_rows() |
Beta Was this translation helpful? Give feedback.
-
This is one of the few things that legitimately runs afoul of the constraints on the layouting engine (particularly once the PR for higher level Ns is merged in, as that was one of the other longstanding limitations). That said, you have a few options for how to get a table to render like that. The first is to write an afun that emits allof the following rows and assigns the appropriate indent modifiers to them:
As in that whole block will be a single analyze call that just looks like a split with partial analyze under it. This will work, though the row paths will be somewhat unintuitive and wanting to sort the rows under "prefer to self-describe" would be difficult at best. The other option is to construct 3 parts and just hid ethat fact from the reader of the table: something along the lines (untested)
The table structure wil be weird here and again, dynamic sorting would be troublesome, but it will look like you want it to when you get the label visibliity and indent mod controls right. If I had to make that table tomorrow I'd probably go with option one, but it depends some on what the downstream processing is. |
Beta Was this translation helpful? Give feedback.
this is what you are looking for: