strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
609 stars 93 forks source link

multiple variables in xtab #190

Open ghost opened 7 years ago

ghost commented 7 years ago

Is it possible to crosstab more than one variable (rows, perhaps by dplyr:select) by several variables (columns), both nested and flat (side by side) so to speak. something like: sjt.xtab(select(q1:q10),select(gender,agecategory))

sjPlot commented 7 years ago

I think this might be a duplicate of https://github.com/sjPlot/devel/issues/97. However, I'm not sure how your example would look like? Several tables, subsetted by select(q1:q10)?

Currently, for console output, you can use sjmisc::flat_table().

ghost commented 7 years ago

Thanks, read up on #97, sjt.mtab sounds interesting. Thank you for your great work!

MarkusLang1987 commented 7 years ago

I guess what he means is to analyse multiple variables and to split for multiple variables:

i tried this with sjt.xtab(c(x_1, v_2, v_10, v_20), c(v_3, v_4).

This would be really awesome, now i filter with dplyr first, but with data with more categories this is quite hard :(

strengejacke commented 7 years ago

If you want to create contingency tables from different groups, you could use dplyr::group_by() and then sjtab(fun = "xtab"). See also ?sjPlot::sjtab.

strengejacke commented 7 years ago

Is this issue solved?

ghost commented 7 years ago

It was more of a wishlist than an issue. There are no further development in sjtab tiwards this right? What I'm looking for is sort of a SPSS custom tables package/function..

MarkusLang1987 commented 7 years ago

Same for me, i would really like to implement some kind of crosstable function in a shiny web app (which anyway seems impossible, since SJplot renders in HTML :(.

strengejacke commented 7 years ago

Perhaps I'm misunderstanding something. Do you like one crosstable with multiple variables (3, 4 or 5 or more), or do mean "grouping", as I suggested here?

MarkusLang1987 commented 7 years ago

What is the exact difference? ;-).

I show you a picture of a project where i use SPSS for.

split

ghost commented 7 years ago

Yes, what MarkusLang showed is what I wish for. something like:

df %>% xtab(select(., var1:var5), select(., gender, agevcat, martialstatus), weights = weight, ... options)

ghost commented 7 years ago

This,

efc %>% group_by(e16sex, c172code) %>% select(e42dep, n4pstu, e16sex, c172code) %>% sjtab(fun = "xtab", use.viewer = FALSE)

gives me 6 tables, whereas I would rather put gender and level of education as BY variables

strengejacke commented 7 years ago

Still a bit confused... Could you post a screenshot of the desired graphical output?

MarkusLang1987 commented 7 years ago

Like this: split2

ghost commented 7 years ago

bild

This with the efc data

MarkusLang1987 commented 7 years ago

Yes, but this only works with one variable, not for multiple variables, right?

If im wrong, can you please show me the output?

ghost commented 7 years ago

No, I can add any number of variables to table rows:

bild

ghost commented 7 years ago

If there was an R-package for these kinds of tables, and if they could also be exported to a spreadsheet.. so nice

MarkusLang1987 commented 7 years ago

This is exactly what i need!! Can you show me an example Syntax?

ghost commented 7 years ago

I can, but I don't want to clutter this thread with that, where can I contact you?

henkar91 commented 7 years ago

I'm also looking for a package that can produce the output above!!

MarkusLang1987 commented 7 years ago

langmarkus@hotmail.com

strengejacke commented 7 years ago

These are "just" combined tables... Shouldn't be too difficult to implement.

I thought you were looking for something like this:

library(sjmisc)
data(efc)
flat_table(efc, c161sex, c172code, n4pstu)

# or
flat_table(efc, c161sex, c172code, n4pstu, e42dep)
ghost commented 7 years ago

If you'd ever find time to implement something like this to sjPlot, I'd be more than willing to help out, like testing or such. Great work Daniel!