view_df {sjPlot}

Ressources:

(back to table of content)

Basics of the sjt-functions

Please refer to this document

Inspecting data frames and imported data

Before using the functions of the sjPlot package, it might be useful to assign value and variable labels to variables (vectors) or data frames. If you are using the read_spss function to import SPSS data, value labels are automatically attached to the data frame. With the attach.var.labels parameter, variable labels will be automatically attached, too.

my_dataframe <- read_spss("path/to/spss-file.sav",  # file path to sav-file
                          enc = "UTF-8",            # may be necessary
                          attach.var.labels = TRUE) # attach variable labels
                                                    # to vectors as well

With attached value and variable labels, most functions of this package automatically detect labels and uses them as axis, legend or title labels in plots (sjp.-functions) respectively as column or row headers in table outputs (sjt.-functions).

Note that factor variables do not necessarily be converted to numeric vectors. Factor levels will automatically be used as variable labels.

For further details on data import, please refer to this document

Let’s initialize the example data set:

#load package
library(sjPlot)
library(sjmisc)
# load sample data set. this data frame has value and variable
# label attributes that can be accessed with "get_labels"
# and "get_label"
data(efc)

Display variables and associated value

Once you have a data frame, e.g. an imported data set from SPSS using read_spss, you can create an overview of all variable with their associated labels and value with the view_df function:

view_df(efc)
Data frame: efc
ID Name Label Values Value Labels
1 c12hour average number of hours of care per week
2 e15relat relationship to elder 1
2
3
4
5
6
7
8
spouse/partner
child
sibling
daughter or son -in-law
ancle/aunt
nephew/niece
cousin
other, specify
3 e16sex elder’s gender 1
2
male
female
4 e17age elder’ age
5 e42dep elder’s dependency 1
2
3
4
independent
slightly dependent
moderately dependent
severely dependent
6 c82cop1 do you feel you cope well as caregiver? 1
2
3
4
never
sometimes
often
always
7 c83cop2 do you find caregiving too demanding? 1
2
3
4
Never
Sometimes
Often
Always
8 c84cop3 does caregiving cause difficulties in your
relationship with your friends?
1
2
3
4
Never
Sometimes
Often
Always
9 c85cop4 does caregiving have negative effect on your
physical health?
1
2
3
4
Never
Sometimes
Often
Always
10 c86cop5 does caregiving cause difficulties in your
relationship with your family?
1
2
3
4
Never
Sometimes
Often
Always
11 c87cop6 does caregiving cause financial difficulties? 1
2
3
4
Never
Sometimes
Often
Always
12 c88cop7 do you feel trapped in your role as caregiver? 1
2
3
4
Never
Sometimes
Often
Always
13 c89cop8 do you feel supported by friends/neighbours? 1
2
3
4
never
sometimes
often
always
14 c90cop9 do you feel caregiving worthwhile? 1
2
3
4
never
sometimes
often
always
15 c160age carer’ age
16 c161sex carer’s gender 1
2
Male
Female
17 c172code carer’s level of education 1
2
3
low level of education
intermediate level of education
high level of education
18 c175empl are you currently employed? 0
1
no
yes
19 barthtot Total score BARTHEL INDEX
20 neg_c_7 Negative impact with 7 items
21 pos_v_4 Positive value with 4 items
22 quol_5 Quality of life 5 items
23 resttotn Job restrictions
24 tot_sc_e Services for elderly
25 n4pstu Care level 0
1
2
3
4
No Care Level
Care Level 1
Care Level 2
Care Level 3
Care Level 3+
26 nur_pst Care level 1
2
3
Care Level 1
Care Level 2
Care Level 3/3+

Add additional statistics

You have several options to remove or add columns with specific information, e.g. show.values or show.labels to show variable values and value labels, or show.frq to show the frequencies in each category.

view_df(efc, show.frq = TRUE, show.prc = TRUE)
Data frame: efc
ID Name Label Values Value Labels Freq. %
1 c12hour average number of hours of care per week
2 e15relat relationship to elder 1
2
3
4
5
6
7
8
spouse/partner
child
sibling
daughter or son -in-law
ancle/aunt
nephew/niece
cousin
other, specify
171
473
29
85
23
22
6
92
18.98
52.50
3.22
9.43
2.55
2.44
0.67
10.21
3 e16sex elder’s gender 1
2
male
female
296
605
32.85
67.15
4 e17age elder’ age
5 e42dep elder’s dependency 1
2
3
4
independent
slightly dependent
moderately dependent
severely dependent
66
225
306
304
7.33
24.97
33.96
33.74
6 c82cop1 do you feel you cope well as caregiver? 1
2
3
4
never
sometimes
often
always
3
97
591
210
0.33
10.77
65.59
23.31
7 c83cop2 do you find caregiving too demanding? 1
2
3
4
Never
Sometimes
Often
Always
186
547
130
39
20.62
60.64
14.41
4.32
8 c84cop3 does caregiving cause difficulties in your
relationship with your friends?
1
2
3
4
Never
Sometimes
Often
Always
516
252
82
52
57.21
27.94
9.09
5.76
9 c85cop4 does caregiving have negative effect on your
physical health?
1
2
3
4
Never
Sometimes
Often
Always
409
346
85
58
45.55
38.53
9.47
6.46
10 c86cop5 does caregiving cause difficulties in your
relationship with your family?
1
2
3
4
Never
Sometimes
Often
Always
626
211
50
15
69.40
23.39
5.54
1.66
11 c87cop6 does caregiving cause financial difficulties? 1
2
3
4
Never
Sometimes
Often
Always
713
131
39
17
79.22
14.56
4.33
1.89
12 c88cop7 do you feel trapped in your role as caregiver? 1
2
3
4
Never
Sometimes
Often
Always
336
374
113
77
37.33
41.56
12.56
8.56
13 c89cop8 do you feel supported by friends/neighbours? 1
2
3
4
never
sometimes
often
always
313
237
241
110
34.74
26.30
26.75
12.21
14 c90cop9 do you feel caregiving worthwhile? 1
2
3
4
never
sometimes
often
always
76
210
300
302
8.56
23.65
33.78
34.01
15 c160age carer’ age
16 c161sex carer’s gender 1
2
Male
Female
215
686
23.86
76.14
17 c172code carer’s level of education 1
2
3
low level of education
intermediate level of education
high level of education
180
506
156
21.38
60.10
18.53
18 c175empl are you currently employed? 0
1
no
yes
518
384
57.43
42.57
19 barthtot Total score BARTHEL INDEX
20 neg_c_7 Negative impact with 7 items
21 pos_v_4 Positive value with 4 items
22 quol_5 Quality of life 5 items
23 resttotn Job restrictions
24 tot_sc_e Services for elderly
25 n4pstu Care level 0
1
2
3
4
No Care Level
Care Level 1
Care Level 2
Care Level 3
Care Level 3+
410
178
202
104
5
45.61
19.80
22.47
11.57
0.56
26 nur_pst Care level 1
2
3
Care Level 1
Care Level 2
Care Level 3/3+
178
202
109
36.40
41.31
22.29

Sorting columns

You can also sort the variables either by their ID (i.e. column number) or variable name.

view_df(efc, sort.by.name = TRUE)
Data frame: efc
ID Name Label Values Value Labels
19 barthtot Total score BARTHEL INDEX
1 c12hour average number of hours of care per week
15 c160age carer’ age
16 c161sex carer’s gender 1
2
Male
Female
17 c172code carer’s level of education 1
2
3
low level of education
intermediate level of education
high level of education
18 c175empl are you currently employed? 0
1
no
yes
6 c82cop1 do you feel you cope well as caregiver? 1
2
3
4
never
sometimes
often
always
7 c83cop2 do you find caregiving too demanding? 1
2
3
4
Never
Sometimes
Often
Always
8 c84cop3 does caregiving cause difficulties in your
relationship with your friends?
1
2
3
4
Never
Sometimes
Often
Always
9 c85cop4 does caregiving have negative effect on your
physical health?
1
2
3
4
Never
Sometimes
Often
Always
10 c86cop5 does caregiving cause difficulties in your
relationship with your family?
1
2
3
4
Never
Sometimes
Often
Always
11 c87cop6 does caregiving cause financial difficulties? 1
2
3
4
Never
Sometimes
Often
Always
12 c88cop7 do you feel trapped in your role as caregiver? 1
2
3
4
Never
Sometimes
Often
Always
13 c89cop8 do you feel supported by friends/neighbours? 1
2
3
4
never
sometimes
often
always
14 c90cop9 do you feel caregiving worthwhile? 1
2
3
4
never
sometimes
often
always
2 e15relat relationship to elder 1
2
3
4
5
6
7
8
spouse/partner
child
sibling
daughter or son -in-law
ancle/aunt
nephew/niece
cousin
other, specify
3 e16sex elder’s gender 1
2
male
female
4 e17age elder’ age
5 e42dep elder’s dependency 1
2
3
4
independent
slightly dependent
moderately dependent
severely dependent
25 n4pstu Care level 0
1
2
3
4
No Care Level
Care Level 1
Care Level 2
Care Level 3
Care Level 3+
20 neg_c_7 Negative impact with 7 items
26 nur_pst Care level 1
2
3
Care Level 1
Care Level 2
Care Level 3/3+
21 pos_v_4 Positive value with 4 items
22 quol_5 Quality of life 5 items
23 resttotn Job restrictions
24 tot_sc_e Services for elderly

Display data description

You can create a table with the data frame’s variable description with the sjt.df function. This function uses the describe function from the psych package and wraps the results into an HTML table:

sjt.df(efc)
Variable vars n missings missings (percentage) mean sd median trimmed mad min max range skew kurtosis se
c12hour 1 902 6 0.66 42.4 50.81 20 31.43 17.79 4 168 164 1.65 1.31 1.69
e15relat 2 901 7 0.77 2.85 2.08 2 2.44 0 1 8 7 1.55 1.21 0.07
e16sex 3 901 7 0.77 1.67 0.47 2 1.71 0 1 2 1 -0.73 -1.47 0.02
e17age 4 891 17 1.87 79.12 8.09 79 79.05 8.9 65 103 38 0.06 -0.83 0.27
e42dep 5 901 7 0.77 2.94 0.94 3 3.02 1.48 1 4 3 -0.42 -0.84 0.03
c82cop1 6 901 7 0.77 3.12 0.58 3 3.15 0 1 4 3 -0.12 0.25 0.02
c83cop2 7 902 6 0.66 2.02 0.72 2 1.98 0 1 4 3 0.65 0.71 0.02
c84cop3 8 902 6 0.66 1.63 0.87 1 1.47 0 1 4 3 1.3 0.84 0.03
c85cop4 9 898 10 1.1 1.77 0.87 2 1.63 1.48 1 4 3 1.05 0.47 0.03
c86cop5 10 902 6 0.66 1.39 0.67 1 1.26 0 1 4 3 1.76 2.84 0.02
c87cop6 11 900 8 0.88 1.29 0.64 1 1.13 0 1 4 3 2.42 5.71 0.02
c88cop7 12 900 8 0.88 1.92 0.91 2 1.8 1.48 1 4 3 0.82 -0.09 0.03
c89cop8 13 901 7 0.77 2.16 1.04 2 2.08 1.48 1 4 3 0.32 -1.14 0.03
c90cop9 14 888 20 2.2 2.93 0.96 3 3.02 1.48 1 4 3 -0.45 -0.84 0.03
c160age 15 901 7 0.77 53.46 13.35 54 53.68 14.83 18 89 71 -0.14 -0.4 0.44
c161sex 16 901 7 0.77 1.76 0.43 2 1.83 0 1 2 1 -1.22 -0.5 0.01
c172code 17 842 66 7.27 1.97 0.63 2 1.96 0 1 3 2 0.02 -0.5 0.02
c175empl 18 902 6 0.66 0.43 0.49 0 0.41 0 0 1 1 0.3 -1.91 0.02
barthtot 19 883 25 2.75 64.55 29.54 70 67.55 29.65 0 100 100 -0.73 -0.54 0.99
neg_c_7 20 892 16 1.76 11.85 3.86 11 11.41 2.97 7 28 21 1.12 1.26 0.13
pos_v_4 21 881 27 2.97 12.48 2.24 13 12.58 2.97 5 16 11 -0.37 -0.36 0.08
quol_5 22 897 11 1.21 14.37 5.31 15 14.76 5.93 0 25 25 -0.59 -0.19 0.18
resttotn 23 908 0 0 0.33 0.68 0 0.16 0 0 4 4 2.24 4.93 0.02
tot_sc_e 24 908 0 0 1.01 1.28 1 0.78 1.48 0 9 9 1.87 5.11 0.04
n4pstu 25 899 9 0.99 1.02 1.09 1 0.89 1.48 0 4 4 0.6 -0.95 0.04
nur_pst 26 489 419 46.15 1.86 0.75 2 1.82 1.48 1 3 2 0.24 -1.22 0.03

Display data frame’s content

When you set describe = FALSE, you can display the content (all values) of a data frame. Be careful: This function may be very slow on large data frames!

sjt.df(efc[1:50, ], describe = FALSE)
Variable c12hour e15relat e16sex e17age e42dep c82cop1 c83cop2 c84cop3 c85cop4 c86cop5 c87cop6 c88cop7 c89cop8 c90cop9 c160age c161sex c172code c175empl barthtot neg_c_7 pos_v_4 quol_5 resttotn tot_sc_e n4pstu nur_pst
1 16 2 2 83 3 3 2 2 2 1 1 2 3 3 56 2 2 1 75 12 12 14 0 4 0 NA
2 148 2 2 88 3 3 3 3 3 4 1 3 2 2 54 2 2 1 75 20 11 10 4 0 0 NA
3 70 1 2 82 3 2 2 1 4 1 1 1 4 3 80 1 1 0 35 11 13 7 0 1 2 2
4 168 1 2 67 4 4 1 3 1 1 1 1 2 4 69 1 2 0 0 10 15 12 2 0 3 3
5 168 2 2 84 4 3 2 1 2 2 2 1 4 4 47 2 2 0 25 12 15 19 2 1 2 2
6 16 2 2 85 4 2 2 3 3 3 2 2 1 1 56 1 2 1 60 19 9 8 1 3 2 2
7 161 1 1 74 4 4 2 4 1 1 2 4 1 4 61 2 2 0 5 15 13 20 0 0 3 3
8 110 4 2 87 4 3 2 2 1 1 1 2 3 3 67 2 2 0 35 11 14 20 0 1 1 1
9 28 2 2 79 4 3 2 3 2 2 1 3 1 3 59 2 NA 0 15 15 13 8 0 2 3 3
10 40 2 2 83 4 3 2 1 2 1 1 1 1 3 49 2 2 0 0 10 13 15 1 1 3 3
11 100 1 1 68 4 3 4 4 4 4 4 4 1 1 66 2 2 0 25 28 9 1 1 1 3 3
12 25 8 2 97 3 3 3 3 1 3 1 4 3 1 47 2 2 1 85 18 8 19 1 1 1 1
13 25 2 2 80 4 3 2 2 2 2 1 2 4 4 58 2 3 0 15 13 14 12 0 3 3 3
14 24 1 2 75 3 3 2 4 4 1 1 2 4 4 75 1 1 0 70 18 14 8 0 0 1 1
15 56 2 2 82 3 2 3 3 3 2 2 1 1 1 49 2 3 1 NA 16 9 8 3 3 0 NA
16 20 2 2 89 3 4 2 1 3 3 1 2 1 3 56 2 2 0 0 13 14 6 0 2 0 NA
17 25 1 1 80 1 3 2 1 2 1 1 2 4 4 75 2 2 0 95 11 15 16 0 2 0 NA
18 126 1 1 72 3 4 2 1 2 1 1 2 3 3 70 2 2 0 55 11 13 14 0 0 2 2
19 168 2 1 94 3 3 2 1 2 2 1 3 1 4 52 1 3 1 55 13 13 15 3 1 1 1
20 118 1 1 79 4 3 2 4 2 1 3 3 2 2 48 2 3 1 45 17 12 10 0 7 2 2
21 150 2 2 89 4 3 2 3 2 1 1 1 1 3 58 2 2 1 0 11 11 15 1 1 4 3
22 50 1 1 67 3 4 1 2 1 1 1 1 2 2 65 2 2 0 70 9 12 21 0 0 1 1
23 18 2 2 94 4 3 1 1 1 1 1 1 2 4 49 2 2 1 20 8 15 18 1 0 2 2
24 168 2 2 83 4 3 2 2 4 1 1 2 3 4 60 2 2 0 0 14 15 15 1 1 3 3
25 15 2 2 85 3 3 2 1 2 1 1 2 3 3 55 2 2 0 95 11 14 16 0 2 1 1
26 168 1 1 80 4 2 3 4 4 3 1 4 1 4 62 2 2 0 10 23 12 0 1 1 2 2
27 12 2 2 88 4 2 3 3 NA 1 1 4 2 2 68 2 3 0 75 NA 10 10 0 5 2 2
28 7 1 1 76 2 2 2 2 2 1 1 1 3 2 76 2 2 0 90 11 9 14 0 2 0 NA
29 35 2 2 84 3 3 2 2 2 4 1 2 2 1 58 2 2 0 60 15 11 4 0 2 2 2
30 168 2 2 95 4 2 2 1 2 1 1 1 2 4 65 2 1 0 20 11 NA 15 0 0 3 3
31 150 2 1 88 4 3 2 4 4 4 4 4 1 3 63 1 2 1 NA 25 13 9 1 2 3 3
32 168 1 1 87 4 3 1 3 1 1 1 1 1 4 79 2 1 0 50 9 12 18 0 1 2 2
33 168 4 2 89 3 3 2 2 3 1 1 3 1 1 65 2 2 0 75 15 9 12 0 1 1 1
34 119 1 1 80 4 2 2 4 4 2 1 4 2 3 74 2 2 0 50 20 12 1 0 7 3 3
35 168 1 2 75 4 3 2 1 2 1 1 1 3 4 76 1 2 0 30 9 15 4 0 4 3 3
36 168 1 1 82 4 3 2 1 2 1 1 1 4 4 73 2 1 0 0 10 14 13 0 1 3 3
37 168 1 1 69 4 3 4 3 2 1 1 4 1 1 67 2 2 0 30 19 9 4 0 6 3 3
38 28 2 2 91 2 3 1 1 2 1 1 1 4 4 62 2 2 0 90 8 14 16 1 1 0 NA
39 168 1 1 86 4 3 2 3 4 1 3 2 1 4 80 2 2 0 15 17 15 11 1 5 3 3
40 30 2 2 86 3 2 3 2 3 2 1 2 3 3 49 2 2 1 70 16 12 5 2 5 1 1
41 14 2 2 84 3 4 3 2 2 3 1 4 1 3 46 2 3 1 85 17 12 11 0 1 1 1
42 168 1 1 69 4 4 2 1 3 1 3 2 1 4 68 2 2 0 NA 14 14 14 1 3 3 3
43 168 1 1 67 4 3 2 3 3 1 2 1 3 3 62 2 3 0 0 14 11 8 0 3 3 3
44 50 1 1 67 4 3 3 2 3 2 1 3 1 2 65 2 2 0 30 16 11 16 0 4 3 3
45 168 1 1 66 4 3 4 2 2 2 2 4 2 2 63 2 2 0 60 19 12 9 0 4 3 3
46 24 1 1 79 4 2 3 1 3 1 2 4 3 1 81 2 2 0 25 NA 10 13 0 0 3 3
47 168 1 2 72 4 3 2 3 3 1 4 2 1 2 72 1 2 0 NA 17 9 9 0 3 3 3
48 42 1 1 65 4 3 3 2 3 1 1 2 3 3 64 2 NA 0 30 15 12 9 0 2 2 2
49 154 1 1 75 3 3 2 3 3 1 1 3 2 4 73 2 NA 0 85 16 14 14 0 1 1 1
50 60 7 2 87 4 2 4 4 3 1 1 3 2 1 73 2 2 0 0 19 6 18 0 2 3 3