forked from WdeNooy/Statistical-Inference
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathR_setup.R
More file actions
55 lines (50 loc) · 1.49 KB
/
R_setup.R
File metadata and controls
55 lines (50 loc) · 1.49 KB
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
54
55
# List of packages needed for the project
list.of.packages <- c("tidyverse",
"knitr",
"kableExtra",
"visNetwork",
"RColorBrewer",
"ggplot2",
"dplyr",
"stringr")
# Install missing packages
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if (length(new.packages)) install.packages(new.packages)
# Load required libraries
library(tidyverse)
library(knitr)
library(kableExtra)
library(visNetwork)
library(RColorBrewer)
library(ggplot2)
library(dplyr)
library(stringr)
#General ggplot2 theme
theme_general <- function() {
theme_classic() +
theme(
text = element_text(size = 12),
plot.title = element_text(hjust = 0.5, size = 13),
panel.border=element_rect(fill=NA)
)
}
# Standard colors to use
brewercolors <- brewer.pal( 5, name = "Spectral")
brewercolors[3] <- "#ffff00"
names(brewercolors) <- c("Red", "Orange", "Yellow", "Green", "Blue")
# Function to print p values.
pprint <- function(pvalue) {
ifelse(pvalue < .0005,
"p < .001",
paste0("p = ", format(round(pvalue,3), nsmall = 3)))
}
# Function to print (numeric) results except p values.
rprint <- function(value) {
format(round(value,2), nsmall = 2)
}
# Function to print p values.
pprint <- function(value) {
ifelse(value < 0.001, "p < .001",
paste0("p = ", format(round(value,3), nsmall = 3))
)
}