Instantly share code, notes, and snippets.
Created
April 24, 2020 18:16
-
Save lcolladotor/838c956a6f22cbb7572cc2bd3d7baebf to your computer and use it in GitHub Desktop.
For https://docs.google.com/document/d/13YPVIalTVM-pJ7ldZhiboNzTPJDC_qBySLTTwigE2O4/edit?usp=sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## From https://r-graphics.org/recipe-quick-scatter | |
plot(mtcars$wt, mtcars$mpg) | |
library(ggplot2) | |
ggplot(mtcars, aes(x = wt, y = mpg)) + | |
geom_point() | |
## Check structure of the ggplot object | |
x <- ggplot(mtcars, aes(x = wt, y = mpg)) + | |
geom_point() | |
str(x) | |
## From https://wilkelab.org/cowplot/reference/plot_grid.html | |
library(ggplot2) | |
df <- data.frame( | |
x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4 | |
) | |
p1 <- ggplot(df, aes(x, y1)) + geom_point() | |
p2 <- ggplot(df, aes(x, y2)) + geom_point() | |
p3 <- ggplot(df, aes(x, y3)) + geom_point() | |
p4 <- ggplot(df, aes(x, y4)) + geom_point() | |
# simple grid | |
library("cowplot") | |
plot_grid(p1, p2, p3, p4) | |
## From https://ggobi.github.io/ggally/#ggallyggpairs | |
data(tips, package = "reshape") | |
library("GGally") | |
dim(tips) | |
head(tips) | |
pm <- ggpairs(tips) | |
class(pm) | |
pm | |
## From https://rpkgs.datanovia.com/ggpubr/ | |
# Load data | |
library('ggpubr') | |
data("ToothGrowth") | |
df <- ToothGrowth | |
head(df, 4) | |
dim(df) | |
my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") ) | |
# Violin plots with box plots inside | |
# ::::::::::::::::::::::::::::::::::::::::::::::::::: | |
# Change fill color by groups: dose | |
# add boxplot with white fill color | |
ggviolin(df, x = "dose", y = "len", fill = "dose", | |
palette = c("#00AFBB", "#E7B800", "#FC4E07"), | |
add = "boxplot", add.params = list(fill = "white"))+ | |
stat_compare_means(comparisons = my_comparisons, label = "p.signif")+ # Add significance levels | |
stat_compare_means(label.y = 50) # Add global the p-value | |
## From https://github.com/ropensci/plotly#readme | |
library(plotly) | |
g <- ggplot(faithful, aes(x = eruptions, y = waiting)) + | |
stat_density_2d(aes(fill = ..level..), geom = "polygon") + | |
xlim(1, 6) + ylim(40, 100) | |
ggplotly(g) | |
## Go back to our earlier 'x' object | |
ggplotly(x) | |
## Reproducibility information | |
print('Reproducibility information:') | |
Sys.time() | |
proc.time() | |
options(width = 120) | |
sessioninfo::session_info() | |
# ─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────── | |
# setting value | |
# version R version 3.6.3 (2020-02-29) | |
# os macOS Catalina 10.15.4 | |
# system x86_64, darwin15.6.0 | |
# ui RStudio | |
# language (EN) | |
# collate en_US.UTF-8 | |
# ctype en_US.UTF-8 | |
# tz America/New_York | |
# date 2020-04-24 | |
# | |
# ─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
# package * version date lib source | |
# assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) | |
# backports 1.1.6 2020-04-05 [1] CRAN (R 3.6.3) | |
# Cairo 1.5-12 2020-04-11 [1] CRAN (R 3.6.2) | |
# callr 3.4.3 2020-03-28 [1] CRAN (R 3.6.2) | |
# cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.0) | |
# colorout * 1.2-1 2019-05-07 [1] Github (jalvesaq/colorout@7ea9440) | |
# colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0) | |
# cowplot * 1.0.0 2019-07-11 [1] CRAN (R 3.6.0) | |
# crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) | |
# crosstalk 1.1.0.1 2020-03-13 [1] CRAN (R 3.6.0) | |
# data.table 1.12.8 2019-12-09 [1] CRAN (R 3.6.1) | |
# desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) | |
# devtools * 2.3.0 2020-04-10 [1] CRAN (R 3.6.3) | |
# digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.0) | |
# dplyr 0.8.5 2020-03-07 [1] CRAN (R 3.6.0) | |
# ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) | |
# fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.0) | |
# farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.0) | |
# fs 1.4.1 2020-04-04 [1] CRAN (R 3.6.3) | |
# GGally * 1.5.0 2020-03-25 [1] CRAN (R 3.6.0) | |
# ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.0) | |
# ggpubr * 0.2.5 2020-02-13 [1] CRAN (R 3.6.0) | |
# ggsignif 0.6.0 2019-08-08 [1] CRAN (R 3.6.0) | |
# glue 1.4.0 2020-04-03 [1] CRAN (R 3.6.3) | |
# gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0) | |
# hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.0) | |
# htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) | |
# htmlwidgets 1.5.1 2019-10-08 [1] CRAN (R 3.6.0) | |
# httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.0) | |
# isoband 0.2.1 2020-04-12 [1] CRAN (R 3.6.2) | |
# jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.0) | |
# labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0) | |
# lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) | |
# lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.0) | |
# magrittr * 1.5 2014-11-22 [1] CRAN (R 3.6.0) | |
# MASS 7.3-51.5 2019-12-20 [1] CRAN (R 3.6.3) | |
# memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) | |
# munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0) | |
# pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.0) | |
# pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) | |
# pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) | |
# pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) | |
# plotly * 4.9.2.1 2020-04-04 [1] CRAN (R 3.6.2) | |
# plyr 1.8.6 2020-03-03 [1] CRAN (R 3.6.2) | |
# prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2) | |
# processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.0) | |
# progress 1.2.2 2019-05-16 [1] CRAN (R 3.6.0) | |
# ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.0) | |
# purrr 0.3.4 2020-04-17 [1] CRAN (R 3.6.2) | |
# R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) | |
# RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0) | |
# Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.3) | |
# remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.0) | |
# reshape 0.8.8 2018-10-23 [1] CRAN (R 3.6.0) | |
# rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.0) | |
# rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) | |
# rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.0) | |
# scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1) | |
# sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) | |
# testthat * 2.3.2 2020-03-02 [1] CRAN (R 3.6.2) | |
# tibble 3.0.1 2020-04-20 [1] CRAN (R 3.6.3) | |
# tidyr 1.0.2 2020-01-24 [1] CRAN (R 3.6.2) | |
# tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.0) | |
# usethis * 1.6.0 2020-04-09 [1] CRAN (R 3.6.3) | |
# vctrs 0.2.4 2020-03-10 [1] CRAN (R 3.6.0) | |
# viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0) | |
# withr 2.2.0 2020-04-20 [1] CRAN (R 3.6.3) | |
# yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.0) | |
# | |
# [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment