## ----setup, include=FALSE-----------------------------------------------------
#knitr::opts_chunk$\alphaet(echo = FALSE)
knitr::opts_chunk$set(message = FALSE, eval=FALSE)
knitr::opts_chunk$set(fig.align = "center") #solo para html
knitr::opts_chunk$set(fig.width = 8)
knitr::opts_chunk$set(dpi = 1200)

## ----echo=TRUE, warning=FALSE, message=FALSE----------------------------------
# library(RIFanalysis)

## -----------------------------------------------------------------------------
# data_gr1 <- read.csv("0_data_gr1.csv")
# data_gr2 <- read.csv("0_data_gr2.csv")

## -----------------------------------------------------------------------------
# # Review required variable names (ALWAYS verify them in the dataset)
# fact_lbl_prefix1        <- "gr1T"                # Choose according to your needs (gr=group, T=topic, C=concept, F=factor, I=index, etc.)
# var_factor_name1        <- "factor"              # Long/original FACTOR variable
# var_factor_small1       <- "factor_small"        # Short FACTOR variable
# var_factor_label_small1 <- "factor_label_small"  # FACTOR_label_small variable
# var_count_name1         <- "count"               # COUNT variable
# 
# fact_lbl_prefix2        <- "gr2T"                # Choose according to your needs (gr=group, T=topic, C=concept, F=factor, I=index, etc.)
# var_factor_name2        <- "factor"              # Long/original FACTOR variable
# var_factor_small2       <- "factor_small"        # Short FACTOR variable
# var_factor_label_small2 <- "factor_label_small"  # FACTOR_label_small variable
# var_count_name2         <- "count"               # COUNT variable
# 
# # Assign a common Type label to all observations because the datasets do not contain a Type variable.
# var_type_value_name1  <- "corpus_type"  # Option B (abstract, index, etc.)
# var_type_value_name2  <- "corpus_type"  # Option B (abstract, index, etc.)
# 
# # Assign labels identifying the groups to be compared.
# gr_value_name1  <- "gr1_NAME"  # Change (Colombia, Greece, Blue Economy, etc.)
# gr_value_name2  <- "gr2_NAME"  # Change (Colombia, Greece, Blue Economy, etc.)
# #prefix_name <- paste0(gr_name, "_")
# 
# #________________________________________________________________________
# #
# 
# # If desired, change axis title  for RIF matrices (Topic, Concept, Factor, etc.) and labels.
# # IN rif_workflow_z3, SEE plot_matrix.R FUNCTION:
# 
# # Axis title:
# x_title_name  <-  "s: CHANGE_NAME at rank s" # default: Concept
# y_title_name  <-  "r: CHANGE_NAME at rank r" # default: Concept
# # Axis labels:
# factor_r_label_col_name <- "Factor_label" # default: factor_r_label_col = NULL
# factor_s_label_col_name <- "Factor_label" # default: factor_s_label_col = NULL
# 
# #________________________________________________________________________
# #
# # Customize titles for power-law plots generated by rif_workflow_z2() and plot_zipf().
# # Title default is "Observed and theoretical Zipf distributions..."
# title_plotzipf_gr1_c2 <- "GROUPNAME1" # Change if desired
# title_plotzipf_gr2_c2 <- "GROUPNAME2" # Change if desired
# 
# x_title_plotzipf_c2   <- "Position"  # Change if desired (default="Rank")
# y_title_plotzipf_c2   <- "Frequency" # Change if desired (default="Count")
# 
# #________________________________________________________________________
# #
# 
# # Change custom file names (if desired)
# file_prefix_no_title     <- "zipf_notitle"
# file_prefix_yes_title_c1 <- "zipf_yestitle_c1"
# file_prefix_yes_title_c2 <- "zipf_yestitle_c2"
# 
# # Change output directories (if desired)
# output_dir_personal   <- file.path(tempdir(), "Z0_personal")
# output_dir_comparison <- file.path(tempdir(), "Z2_RIF_comparison")
# output_dir_visual     <- file.path(tempdir(), "Z3_RIF_visual")

## -----------------------------------------------------------------------------
# rif_data1 <- rif_prepare(data= data_gr1,
#     factor_col = var_factor_name1,
#     count_col = var_count_name1,
#     factor_small_col = var_factor_small1,
#     group_col = NULL,
#     type_col = NULL,
#     group_value = gr_value_name1,
#     type_value = var_type_value_name1,
#     prefix = fact_lbl_prefix1,
#     factor_small_label_style = "inline")
# 
# rif_data1
# names(rif_data1)

## -----------------------------------------------------------------------------
# rif_data2 <- rif_prepare(data= data_gr2,
#     factor_col = var_factor_name2,
#     count_col = var_count_name2,
#     factor_small_col = var_factor_small2,
#     group_col = NULL,
#     type_col = NULL,
#     group_value = gr_value_name2,
#     type_value = var_type_value_name2,
#     prefix = fact_lbl_prefix2,
#     factor_small_label_style = "inline")
# 
# rif_data2
# names(rif_data2)

## -----------------------------------------------------------------------------
# z2 <- rif_workflow_z2(
#     rif_data1 = rif_data1,
#     rif_data2 = rif_data2,
#     alpha_zipf = 1,
#     no_of_sims = 1000,
#     threads = 8,
#     seed = 123,
#     bootstrap_engine = "poweRlaw",
#     output_dir = output_dir_comparison,
#     plot_formats = c("png", "pdf")
#     )

## ----eval=FALSE---------------------------------------------------------------
# z2$input1
# z2$input2
# 
# z2$data1
# z2$data2
# 
# z2$zipf1
# z2$zipf2
# 
# z2$analysis1
# z2$analysis2
# 
# z2$rif_results1
# z2$rif_results2
# 
# z2$rif_comparison
# z2$plots
# z2$files

## -----------------------------------------------------------------------------
# rif_workflow_z3(
#   x = z2$rif_comparison,
#   scope = "combined",
#   plot_types = c("matrix", "network"),
#   formats = c("png", "pdf"),
#   #plot_types = "matrix",
#   output_dir = output_dir_visual,
# 
#   #SEE plot_matrix.R FUNCTION:
#   matrix_args = list(
#     #factor_r_label_col = factor_r_label_col_name,
#     factor_s_label_col = factor_s_label_col_name,
#     x_title = x_title_name,
#     y_title = y_title_name
#     )
# )

## -----------------------------------------------------------------------------
# z2$plots$group1
# z2$plots$group2
# 
# z2$files$group1
# z2$files$group2
# 
# z2$files$plots
# z2$files$excel

