plot_correlate.tbl_dbi: Visualize correlation plot of numerical data

Description Usage Arguments Details See Also Examples

Description

The plot_correlate() visualize correlation plot for find relationship between two numerical(INTEGER, NUMBER, etc.) column of the DBMS table through tbl_dbi.

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'tbl_dbi'
plot_correlate(
  .data,
  ...,
  in_database = FALSE,
  collect_size = Inf,
  method = c("pearson", "kendall", "spearman")
)

Arguments

.data

a tbl_dbi.

...

one or more unquoted expressions separated by commas. You can treat variable names like they are positions. Positive values select variables; negative values to drop variables. If the first expression is negative, plot_correlate() will automatically start with all variables. These arguments are automatically quoted and evaluated in a context where column names represent column positions. They support unquoting and splicing.

in_database

Specifies whether to perform in-database operations. If TRUE, most operations are performed in the DBMS. if FALSE, table data is taken in R and operated in-memory. Not yet supported in_database = TRUE.

collect_size

a integer. The number of data samples from the DBMS to R. Applies only if in_database = FALSE.

method

a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson" (default), "kendall", or "spearman": can be abbreviated.

See vignette("EDA") for an introduction to these concepts.

Details

The scope of the visualization is the provide a correlation information. Since the plot is drawn for each variable, if you specify more than one variable in the ... argument, the specified number of plots are drawn.

See Also

plot_correlate.data.frame, plot_outlier.tbl_dbi.

Examples

 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
library(dplyr)

# connect DBMS
con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

# copy heartfailure to the DBMS with a table named TB_HEARTFAILURE
copy_to(con_sqlite, heartfailure, name = "TB_HEARTFAILURE", overwrite = TRUE)

# Using pipes ---------------------------------
# Visualize correlation plot of all numerical variables
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  plot_correlate()
  
# Positive values select variables, and In-memory mode and collect size is 200
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  plot_correlate(platelets, sodium, collect_size = 200)
  
# Negative values to drop variables
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  plot_correlate(-platelets, -sodium)
  
# Positions values select variables
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  plot_correlate(1)
  
# Positions values select variables
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  plot_correlate(-1, -2, -3, -5, -6)

# Using pipes & dplyr -------------------------
# Visualize correlation plot of 'sodiumsodium' variable by 'smoking'
# and 'death_event' variables.
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  group_by(smoking, death_event) %>%
  plot_correlate(sodium)

# Extract only those with 'smoking' variable level is "Yes",
# and visualize correlation plot of 'sodium' variable by 'sex'
# and 'death_event' variables.
con_sqlite %>% 
  tbl("TB_HEARTFAILURE") %>% 
  filter(smoking == "Yes") %>%
  group_by(sex, death_event) %>%
  plot_correlate(sodium)

# Disconnect DBMS   
DBI::dbDisconnect(con_sqlite)

bit2r/kodlookr documentation built on Dec. 19, 2021, 9:49 a.m.