How to create graphs with ggplot2 in R

Package The packages are additional functionalities that can be installed to Rstudio. Think of the apps on your phone, which can do different things. There are several ways to install them, but the simplest is through a package called pacman, but first we need to install the package pacman if (!require("pacman")) install.packages("pacman") Then, every time we need a new package, we invoke the command by pacman::p_load(tidyverse, palmerpenguins) The packages are installed only once (just like the apps on your phone), but you need to call them every time you want to use them (just like the apps on your phone) [Read More]

ggplots tips and tricks

Is your background a different color than white? Use a transparent background: ggsave("myplot.tiff", dpi = 300, plot = myplot, bg = "transparent") To save your images in a high quality format that can be scaled for printing in a magazine or on a poster ggsave("myplot.tiff", dpi = 300, plot = myplot) Match your poster aesthetic with scale_fill_manual(values = c("#__", "#__", etc) Check this also Need more adjustments for your graph? [Read More]

Post

Original from https://www.youtube.com/watch?v=ZM04jn95YP0 install.packages(“tidyverse”) library(tidyverse) ## ── Attaching packages ─────────────────────────────── tidyverse 1.3.0 ── ## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4 ## ✓ tibble 3.0.3 ✓ dplyr 1.0.0 ## ✓ tidyr 1.1.0 ✓ stringr 1.4.0 ## ✓ readr 1.3.1 ✓ forcats 0.5.0 ## ── Conflicts ────────────────────────────────── tidyverse_conflicts() ── ## x dplyr::filter() masks stats::filter() ## x dplyr::lag() masks stats::lag() library(lubridate) ## ## Attaching package: 'lubridate' ## The following objects are masked from 'package:base': ## ## date, intersect, setdiff, union # install. [Read More]

Epidemiological analysis with R

Riga Stradins University Workshop, July 2020

Lecturer: Sergio Uribe, Assoc Prof, PhD Riga Stradins University, July 2020 Required packages pacman::p_load( car, broom, tidyverse, ggfortify, mosaic, huxtable, jtools, latex2exp, pubh, sjlabelled, sjPlot, sjmisc ) theme_set(sjPlot::theme_sjplot2(base_size = 10)) theme_update(legend.position = "top") # options('huxtable.knit_print_df' = FALSE) options('huxtable.knit_print_df_theme' = theme_article) options('huxtable.autoformat_number_format' = list(numeric = "%5.2f")) knitr::opts_chunk$set(collapse = TRUE, comment = NA) Epidemiological Descriptive Analysis Onchocerciasis in Sierra Leone. data(Oncho) Oncho %>% head() idmfareaagegrpsexmfloadlesions 1InfectedSavannah20-39Female1No 2InfectedRainforest40+Male3No 3InfectedSavannah40+Female1No 4Not-infectedRainforest20-39Female0No 5Not-infectedSavannah40+Female0No 6Not-infectedRainforest20-39Female0No A two-by-two contingency table: [Read More]

Regression Modelling for Epidemiology

Riga Stradins University Workshop, July 2020

Lecturer: Sergio Uribe, Assoc Prof, PhD Riga Stradins University, July 2020 pacman::p_load( car, broom, tidyverse, ggfortify, mosaic, huxtable, jtools, latex2exp, pubh, sjlabelled, sjPlot, sjmisc ) theme_set(sjPlot::theme_sjplot2(base_size = 10)) theme_update(legend.position = "top") # options('huxtable.knit_print_df' = FALSE) options('huxtable.knit_print_df_theme' = theme_article) options('huxtable.autoformat_number_format' = list(numeric = "%5.2f")) knitr::opts_chunk$set(collapse = TRUE, comment = NA) Regression data(birthwt, package = "MASS") birthwt <- birthwt %>% mutate(smoke = factor(smoke, labels = c("Non-smoker", "Smoker")), race = factor(race, labels = c("White", "African American", "Other"))) %>% var_labels(bwt = 'Birth weight (g)', smoke = 'Smoking status', race = 'Race') birthwt %>% group_by(race, smoke) %>% summarise( n = n(), Mean = mean(bwt, na. [Read More]

Exploratory Data Analysis with Tables

Introduction Tables allow you to explore and summarize data efficiently. While graphs are more intuitive for discovering relationships and trends, tables have the advantage of providing detailed information and allowing descriptive statistics and data summaries to be delivered. Usually scientific articles in medicine begin with a table that shows the characteristics of the sample of patients. In this post, we will use the janitor and table1 packages to summarize data and make an example of table 1 using the NHANES database. [Read More]

Visualizing the dental workforce of OECD countries I

The Organisation for Economic Co-operation and Development host a database with extensive data. In this post we will do some visualizations to compare the number of dentists in each country. Packages used: tidyverse gghighlight kableExtra First we load the data. Now there is a package (OECD) able to extract the datasets, but I will use a local copy: dent_oecd <- read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vStv7Pr69DtRKv6Nw6gVBep8hbT3pEeO6B1vNwxK_1DUHgpoTgbuRpZ4SvgtHFQnBZJVGeeQVyRuXZl/pub?gid=1330297229&single=true&output=csv") ## Parsed with column specification: ## cols( ## VAR = col_character(), ## Variable = col_character(), ## UNIT = col_character(), ## Measure = col_character(), ## COU = col_character(), ## Country = col_character(), ## YEA = col_double(), ## Year = col_double(), ## Value = col_double(), ## `Flag Codes` = col_character(), ## Flags = col_character() ## ) Always is preferable to take a look the data and its structure: [Read More]

Data wrangling and table summaries of case-control studies

A Case-control study compares patients who have a disease or outcome of interest (cases) with patients who do not have the disease or outcome (controls), and looks back retrospectively to compare how frequently the exposure to a risk factor is present in each group to determine the relationship between the risk factor and the disease. Case control studies are observational because no intervention is attempted and no attempt is made to alter the course of the disease. [Read More]