### Install development version from GitHub Source: https://jumpingrivers.github.io/datasauRus/index.html Use the devtools package to install the latest development version of the package directly from the GitHub repository. ```R devtools::install_github("jumpingrivers/datasauRus") ``` -------------------------------- ### Install stable version from CRAN Source: https://jumpingrivers.github.io/datasauRus/index.html Use this command to install the latest stable release of the datasauRus package from CRAN. ```R install.packages("datasauRus") ``` -------------------------------- ### Load twelve_from_slant_alternate_long dataset Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_alternate_long.html Usage example showing how to access the dataset object in R. ```R twelve_from_slant_alternate_long ``` -------------------------------- ### Plot all datasets in twelve_from_slant_alternate_wide Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_alternate_wide.html This example saves the current graphics parameters, sets up a 4x3 plotting grid with narrow margins, loops over the column pairs to plot each dataset with its name as the title, and restores the original parameters. It assumes the datasauRus package is loaded and the dataset is available. ```R #save current settings state = par("mar", "mfrow") # plot par(mfrow = c(4, 3), mar = c(1, 3, 3, 1)) nms = names(twelve_from_slant_alternate_wide) for (i in seq(1, 23, by = 2)) { nm = substr(nms[i], 1, nchar(nms[i]) - 2) plot(twelve_from_slant_alternate_wide[[nms[i]]], twelve_from_slant_alternate_wide[[nms[i + 1]]], xlab = "", ylab = "", main = nm) } #reset settings par(state) ``` -------------------------------- ### Visualizing the Datasaurus Dozen with Base R Source: https://jumpingrivers.github.io/datasauRus/reference/datasaurus_dozen_wide.html This example iterates through the wide-format dataset to plot each of the 12 shapes in a 5x3 grid, resetting the graphical parameters afterwards. ```R # Save current settings state = par("mar", "mfrow") # Base R Plots par(mfrow = c(5, 3), mar = c(1, 3, 3, 1)) nms = names(datasaurus_dozen_wide) for (i in seq(1, 25, by = 2)) { nm = substr(nms[i], 1, nchar(nms[i]) - 2) plot(datasaurus_dozen_wide[[nms[i]]], datasaurus_dozen_wide[[nms[i + 1]]], xlab = "", ylab = "", main = nm) } #reset settings par(state) ``` -------------------------------- ### Visualize Datasaurus Dozen with ggplot2 Source: https://jumpingrivers.github.io/datasauRus/index.html This example demonstrates how to use ggplot2 to create a faceted plot of the Datasaurus Dozen datasets. ```R library("ggplot2") library("datasauRus") ggplot(datasaurus_dozen, aes(x = x, y = y, colour = dataset))+ geom_point() + theme_void() + theme(legend.position = "none")+ facet_wrap(~dataset, ncol = 3) ``` -------------------------------- ### Base R plots for twelve_from_slant_alternate_long Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_alternate_long.html Base R plotting example that creates a 4x3 grid of scatter plots for each dataset, saving and restoring graphical parameters. ```R # Base R Plots state = par("mfrow", "mar") par(mfrow = c(4, 3), mar = c(2, 2, 2, 2)) sets = sort(unique(twelve_from_slant_alternate_long$dataset)) for (s in sets) { df = twelve_from_slant_alternate_long[twelve_from_slant_alternate_long$dataset == s, ] plot(df$x, df$y, pch = 16, xlab = "", ylab = "") title(s) } par(state) ``` -------------------------------- ### Plot twelve_from_slant_alternate_long with ggplot2 Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_alternate_long.html Example using ggplot2 to create a faceted scatter plot of the dataset, with points colored by dataset and no legend. ```R if (require(ggplot2)) { ggplot(twelve_from_slant_alternate_long, aes(x = x, y = y, colour = dataset)) + geom_point() + theme_void() + theme(legend.position = "none") + facet_wrap(~dataset, ncol = 3) } ``` -------------------------------- ### ggplot2 density plots for box_plots Source: https://jumpingrivers.github.io/datasauRus/reference/box_plots.html Generates density plots for each variable in box_plots using ggplot2. Requires the ggplot2 package; if not installed, the code is skipped. ```R ## ggplot if (require(ggplot2)) { ggplot(box_plots, aes(x = left)) + geom_density() ggplot(box_plots, aes(x = lines)) + geom_density() ggplot(box_plots, aes(x = normal)) + geom_density() ggplot(box_plots, aes(x = right)) + geom_density() ggplot(box_plots, aes(x = split)) + geom_density() } #> Loading required package: ggplot2 ``` -------------------------------- ### Load twelve_from_slant_wide dataset Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_wide.html Access the dataset object directly. It is a data frame with 182 rows and 24 variables, each pair of columns (e.g., bullseye_x and bullseye_y) holding the x- and y-values for one of the 12 datasets. ```r twelve_from_slant_wide ``` -------------------------------- ### Visualize with ggplot2 Source: https://jumpingrivers.github.io/datasauRus/reference/datasaurus_dozen.html Use ggplot2 to create a faceted scatter plot of all 12 datasets. ```R if (require(ggplot2)) { ggplot(datasaurus_dozen, aes(x = x, y = y, colour = dataset)) + geom_point() + theme_void() + theme(legend.position = "none") + facet_wrap(~dataset, ncol = 3) } ``` -------------------------------- ### Load simpsons_paradox_wide dataset Source: https://jumpingrivers.github.io/datasauRus/reference/simpsons_paradox_wide.html Access the built-in dataset object. The dataset is a data frame with 222 rows and 4 variables: simpson_1_x, simpson_1_y, simpson_2_x, and simpson_2_y. ```r simpsons_paradox_wide ``` -------------------------------- ### Visualize datasets with ggplot2 Source: https://jumpingrivers.github.io/datasauRus/articles/Datasaurus.html Create scatter plots for each sub-dataset using ggplot2 to visualize the differences in distribution. ```R if (requireNamespace("ggplot2")) { library(ggplot2) ggplot(datasaurus_dozen, aes(x = x, y = y, colour = dataset)) + geom_point() + theme_void() + theme(legend.position = "none") + facet_wrap(~dataset, ncol = 3) } ``` ```text ## Loading required namespace: ggplot2 ``` -------------------------------- ### Plot all datasets from twelve_from_slant_wide Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_wide.html Plots all 12 datasets in a 4x3 grid by iterating over the column pairs. Saves the current par settings first and restores them at the end with par(state). ```r #save current settings state = par("mar", "mfrow") # plot par(mfrow = c(4, 3), mar = c(1, 3, 3, 1)) nms = names(twelve_from_slant_wide) for (i in seq(1, 23, by = 2)) { nm = substr(nms[i], 1, nchar(nms[i]) - 2) plot(twelve_from_slant_wide[[nms[i]]], twelve_from_slant_wide[[nms[i + 1]]], xlab = "", ylab = "", main = nm) } #reset settings par(state) ``` -------------------------------- ### Accessing the simpsons_paradox dataset Source: https://jumpingrivers.github.io/datasauRus/reference/simpsons_paradox.html The dataset is accessed by calling its name directly. ```R simpsons_paradox ``` -------------------------------- ### Visualize with Base R plots Source: https://jumpingrivers.github.io/datasauRus/reference/datasaurus_dozen.html Iterate through the unique datasets to generate individual scatter plots using Base R graphics. ```R state = par("mar", "mfrow") # plot par(mfrow = c(5, 3), mar = c(1, 2, 2, 1)) sets = sort(unique(datasaurus_dozen$dataset)) for (s in sets) { df = datasaurus_dozen[datasaurus_dozen$dataset == s, ] plot(df$x, df$y, pch = 16) title(s) } #reset settings par(state) ``` -------------------------------- ### Plot simpsons_paradox_wide datasets Source: https://jumpingrivers.github.io/datasauRus/reference/simpsons_paradox_wide.html Plots the two datasets side by side to visualize Simpson's Paradox. Saves the current graphical parameters, sets a 1x2 layout, creates scatter plots for simpson_1 and simpson_2, then restores the original settings. ```r #save current settings state = par("mar", "mfrow") par(mfrow = c(1, 2)) plot(simpsons_paradox_wide[["simpson_1_x"]], simpsons_paradox_wide[["simpson_1_y"]], xlab = "x", ylab = "y", main = "Simpson's Paradox 1") plot(simpsons_paradox_wide[["simpson_2_x"]], simpsons_paradox_wide[["simpson_2_y"]], xlab = "x", ylab = "y", main = "Simpson's Paradox 2") #reset settings par(state) ``` -------------------------------- ### Visualizing simpsons_paradox with Base R Source: https://jumpingrivers.github.io/datasauRus/reference/simpsons_paradox.html Uses base R plotting functions to iterate through the datasets and plot them side-by-side. ```R state = par("mfrow") par(mfrow = c(1, 2)) sets = unique(datasaurus_dozen$dataset) for (i in 1:2) { df = simpsons_paradox[simpsons_paradox$dataset == paste0("simpson_", i), ] plot(df$x, df$y, pch = 16, xlab = "", ylab = "") title(paste0("Simpson\'s Paradox ", i)) } par(state) #> Warning: argument 1 does not name a graphical parameter #> NULL ``` -------------------------------- ### Visualizing simpsons_paradox with ggplot2 Source: https://jumpingrivers.github.io/datasauRus/reference/simpsons_paradox.html Uses ggplot2 to facet the two datasets and display them as scatter plots. ```R if (require(ggplot2)) { ggplot(simpsons_paradox, aes(x = x, y = y, colour = dataset)) + geom_point() + theme(legend.position = "none") + facet_wrap(~dataset, ncol = 3) } ``` -------------------------------- ### Accessing the datasaurus_dozen_wide dataset Source: https://jumpingrivers.github.io/datasauRus/reference/datasaurus_dozen_wide.html The dataset can be accessed directly by its name. ```R datasaurus_dozen_wide ``` -------------------------------- ### Access the twelve_from_slant_alternate_wide dataset Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_alternate_wide.html The dataset is provided as an R object named twelve_from_slant_alternate_wide. It is a data frame with 182 rows and 24 variables, each pair representing x and y coordinates for one of the 12 datasets. ```R twelve_from_slant_alternate_wide ``` -------------------------------- ### Plot twelve_from_slant_long with ggplot2 and base R Source: https://jumpingrivers.github.io/datasauRus/reference/twelve_from_slant_long.html Two plotting approaches for the twelve_from_slant_long dataset. The first uses ggplot2 with faceting by dataset; the second uses base R plots with a loop over the unique datasets and restores the original graphics state with par(state). ```r if (require(ggplot2)) { ggplot(twelve_from_slant_long, aes(x = x, y = y, colour = dataset)) + geom_point() + theme_void() + theme(legend.position = "none") + facet_wrap(~dataset, ncol = 3) } # Base R Plots state = par("mfrow", "mar") par(mfrow = c(4, 3), mar = c(3, 2, 2, 2)) sets = sort(unique(twelve_from_slant_long$dataset)) for (s in sets) { df = twelve_from_slant_long[twelve_from_slant_long$dataset == s, ] plot(df$x, df$y, pch = 16, xlab = "", ylab = "") title(s) } par(state) ``` -------------------------------- ### Access the datasaurus_dozen dataset Source: https://jumpingrivers.github.io/datasauRus/reference/datasaurus_dozen.html The dataset is available as a data frame named datasaurus_dozen. ```R datasaurus_dozen ``` -------------------------------- ### Summarize box_plots dataset Source: https://jumpingrivers.github.io/datasauRus/reference/box_plots.html Displays summary statistics for each variable in the box_plots dataset. The output shows minimum, quartiles, median, mean, and maximum for left, lines, normal, right, and split. ```R summary(box_plots) #> left lines normal right #> Min. :-9.76964 Min. :-9.769575 Min. :-9.76 Min. :-9.760 #> 1st Qu.:-2.68999 1st Qu.:-2.689993 1st Qu.:-2.68 1st Qu.:-2.680 #> Median :-0.00999 Median :-0.007132 Median : 0.00 Median : 0.000 #> Mean :-1.17780 Mean :-0.831733 Mean : 0.00 Mean : 1.174 #> 3rd Qu.: 2.67007 3rd Qu.: 2.670236 3rd Qu.: 2.68 3rd Qu.: 2.680 #> Max. : 9.75025 Max. : 9.756001 Max. : 9.76 Max. : 9.760 #> split #> Min. :-9.769886 #> 1st Qu.:-2.689989 #> Median :-0.003099 #> Mean :-0.003060 #> 3rd Qu.: 2.680000 #> Max. : 9.760000 ``` -------------------------------- ### Calculate summary statistics with dplyr Source: https://jumpingrivers.github.io/datasauRus/articles/Datasaurus.html Use dplyr to group the datasaurus_dozen dataset by the 'dataset' column and calculate the mean, standard deviation, and correlation for each sub-dataset. ```R library(datasauRus) if (requireNamespace("dplyr")) { suppressPackageStartupMessages(library(dplyr)) datasaurus_dozen %>% group_by(dataset) %>% summarize( mean_x = mean(x), mean_y = mean(y), std_dev_x = sd(x), std_dev_y = sd(y), corr_x_y = cor(x, y) ) } ``` ```text ## Loading required namespace: dplyr ``` ```text ## # A tibble: 13 × 6 ## dataset mean_x mean_y std_dev_x std_dev_y corr_x_y ## ## 1 away 54.3 47.8 16.8 26.9 -0.0641 ## 2 bullseye 54.3 47.8 16.8 26.9 -0.0686 ## 3 circle 54.3 47.8 16.8 26.9 -0.0683 ## 4 dino 54.3 47.8 16.8 26.9 -0.0645 ## 5 dots 54.3 47.8 16.8 26.9 -0.0603 ## 6 h_lines 54.3 47.8 16.8 26.9 -0.0617 ## 7 high_lines 54.3 47.8 16.8 26.9 -0.0685 ## 8 slant_down 54.3 47.8 16.8 26.9 -0.0690 ## 9 slant_up 54.3 47.8 16.8 26.9 -0.0686 ## 10 star 54.3 47.8 16.8 26.9 -0.0630 ## 11 v_lines 54.3 47.8 16.8 26.9 -0.0694 ## 12 wide_lines 54.3 47.8 16.8 26.9 -0.0666 ## 13 x_shape 54.3 47.8 16.8 26.9 -0.0656 ``` -------------------------------- ### Base plot: histograms and boxplots for box_plots Source: https://jumpingrivers.github.io/datasauRus/reference/box_plots.html Creates a 5x2 grid of histograms and horizontal boxplots for each variable in box_plots. Saves and restores graphical parameters (mar, mfrow) to avoid side effects. ```R ## base plot #save current settings state = par("mar", "mfrow") par(mfrow = c(5, 2), mar = c(1, 2, 2, 1)) nms = names(box_plots) for (i in 1:5) { nm = nms[i] hist(box_plots[[nms[i]]], breaks = 100, main = nm) boxplot(box_plots[[nms[i]]], horizontal = TRUE) } #reset settings par(state) ``` -------------------------------- ### BibTeX Citation for datasauRus Source: https://jumpingrivers.github.io/datasauRus/authors.html The BibTeX entry for citing the datasauRus package in academic or technical documents. ```bibtex @Manual{, title = {datasauRus: Datasets from the Datasaurus Dozen}, author = {Colin Gillespie and Steph Locke and Rhian Davies and Lucy {D'Agostino McGowan}}, year = {2025}, note = {R package version 0.1.9, https://jumpingrivers.github.io/datasauRus/}, url = {https://github.com/jumpingrivers/datasauRus}, } ``` -------------------------------- ### Access the box_plots dataset Source: https://jumpingrivers.github.io/datasauRus/reference/box_plots.html Loads the box_plots dataset from the datasauRus package. The dataset is a data frame with 2484 rows and 5 variables. ```R box_plots ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.