### Creating a Quantile-Quantile Plot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_qq() function to generate a quantile-quantile plot. ```r tinyplot(data, type = type_qq()) ``` -------------------------------- ### Install tinyplot from R-universe Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Installs the latest development version of the tinyplot package from R-universe. ```r install.packages("tinyplot", repos = "https://grantmcdermott.r-universe.dev") ``` -------------------------------- ### Install tinyplot from CRAN Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Installs the stable version of the tinyplot package from CRAN. ```r install.packages("tinyplot") ``` -------------------------------- ### Plotting an Arbitrary Function Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_function() to plot the output of an arbitrary function. ```r tinyplot(data, type = type_function(fun = sin, from = 0, to = pi)) ``` -------------------------------- ### Fitting a Spline Model Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_spline() function to fit and visualize a spline model. ```r tinyplot(data, type = type_spline()) ``` -------------------------------- ### Fitting a Linear Model Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_lm() function to fit and visualize a linear model. ```r tinyplot(data, type = type_lm()) ``` -------------------------------- ### Fitting a Generalized Linear Model Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_glm() function to fit and visualize a generalized linear model. ```r tinyplot(data, type = type_glm()) ``` -------------------------------- ### Adding a Spineplot Visualization Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_spineplot() function to create spine plots or spinograms, useful for visualizing factor variables. ```r tinyplot(data, type = type_spineplot()) ``` -------------------------------- ### Adding a Rug Plot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_rug() function to add a rug plot to an existing visualization. ```r tinyplot(data, type = type_rug()) ``` -------------------------------- ### Fitting a LOESS Model Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_loess() function to fit and visualize a LOESS (Locally Estimated Scatterplot Smoothing) model. ```r tinyplot(data, type = type_loess()) ``` -------------------------------- ### Generating Ridge Plots (Joy Plots) Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_ridge() function to create ridge plots, also known as Joy plots. ```r tinyplot(data, type = type_ridge()) ``` -------------------------------- ### Summarizing Y values along unique X values Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_summary() function to summarize y values based on unique x values. ```r tinyplot(data, type = type_summary()) ``` -------------------------------- ### Adding a Line with Intercept and Slope Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_abline() function to add a line defined by an intercept and slope. ```r tinyplot(data, type = type_abline(intercept = 1, slope = 2)) ``` -------------------------------- ### Adding Text Annotations Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_text() function to add text annotations to a plot. ```r tinyplot(data, type = type_text()) ``` -------------------------------- ### Adding a Vertical Line Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_vline() function to add a vertical line to a plot. ```r tinyplot(data, type = type_vline(x = 3)) ``` -------------------------------- ### Adding a Horizontal Line Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Example of using the type_hline() function to add a horizontal line to a plot. ```r tinyplot(data, type = type_hline(y = 5)) ``` -------------------------------- ### Load Development Version Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Use pkgload to load the package during interactive development to ensure local changes are tested. ```r pkgload::load_all() # Then test interactively, e.g. plt(Sepal.Length ~ Petal.Length | Species, data = iris) ``` -------------------------------- ### Execute Tests via Makefile and R Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Commands to run the test suite using either the Makefile or R console. ```bash # Via Makefile make testall # Run all tests make testone testfile="inst/tinytest/test-legend.R" # Run single test file # Via R tinytest::run_test_dir("inst/tinytest") tinytest::run_test_file("inst/tinytest/test-legend.R") ``` -------------------------------- ### Handle Resize with recordGraphics Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Wrap coordinate-dependent calculations in recordGraphics to ensure correct re-rendering on device resize. ```r recordGraphics( tinylegend(legend_env), list = list(legend_env = legend_env), env = getNamespace("tinyplot") ) ``` -------------------------------- ### Makefile Development Commands Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Common development tasks available through the project Makefile. ```bash make help # Show all available commands make document # Generate documentation (devtools::document) make check # Full R CMD check make install # Install package locally make website # Build documentation website (altdoc) ``` -------------------------------- ### Create basic plots with tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Demonstrates atomic and formula-based syntax for generating plots using the iris dataset. ```r with(iris, tinyplot(x = Petal.Length, y = Sepal.Length, by = Species)) # atomic tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris) # formula ``` -------------------------------- ### Migrate from plot2 to tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Demonstrates the syntax change required after the package rename from plot2 to tinyplot. ```r library(plot2) plot2(Sepal.Length ~ Petal.Length | Species, iris) ``` ```r library(tinyplot) tinyplot(Sepal.Length ~ Petal.Length | Species, iris) # Or, use the equivalent shorthand `plt` alias plt(Sepal.Length ~ Petal.Length | Species, iris) ``` -------------------------------- ### Coding Conventions Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Standard practices for assignment, function definition, and element access within the package. ```r # Use = not <- x = 5 # Use function() not \() — package requires R >= 4.0.0 compatibility fn = function(x) x^2 # Prefer [[ over $ for element access (no partial matching, works with variables) legend_args[["title"]] settings[["datapoints"]] # NOT: legend_args$title, settings$datapoints ``` -------------------------------- ### Specify Bounds in Formula Interface Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Compare the legacy with() approach to the updated formula interface for specifying ymin and ymax. ```r with(dat, tinyplot(x = x, y = y, by = by ymin = lwr, ymax = upr)) ``` ```r tinyplot(y ~ x | by, dat, ymin = lwr, ymax = upr) ``` -------------------------------- ### Applying a Pre-defined Theme in Tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Shows how to apply a pre-defined theme, such as 'clean', to subsequent plots using the tinytheme() function. Themes affect all plots until explicitly reset. ```r tinytheme("clean") ``` -------------------------------- ### Apply built-in themes Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Sets a persistent theme for plots using tinytheme(). ```r tinytheme("clean2") plt(Sepal.Length ~ Petal.Length | Species, data = iris) plt_add(type = "lm") ``` -------------------------------- ### Resetting to Default Theme in Tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Demonstrates how to reset plot aesthetics to the default settings by calling tinytheme() without any arguments. ```r tinytheme() ``` -------------------------------- ### Using String vs. Functional Type Arguments in Tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Demonstrates the interchangeability of string-based and functional type arguments for plot types. The functional approach offers more flexibility for customization. ```r tinyplot(Nile, type = "hist") ``` ```r tinyplot(Nile, type = type_hist()) ``` -------------------------------- ### Create Histograms Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates histograms for distribution visualization using type_histogram(). Supports frequency/density toggles and faceting. ```r # Basic histogram tinyplot(Nile, type = "histogram") # Customize number of breaks tinyplot(Nile, type = type_histogram(breaks = 30)) # Density instead of frequency tinyplot(Nile, type = type_histogram(breaks = 30, freq = FALSE)) # Grouped histogram tinyplot(~Petal.Width | Species, type = "histogram", data = iris) # Faceted histogram with free scales tinyplot( ~Petal.Width, facet = ~Species, facet.args = list(free = TRUE), type = type_histogram(free.breaks = TRUE), data = iris ) ``` -------------------------------- ### Apply and View Plot Themes Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Sets persistent visual themes for plots using `tinytheme()`. Themes control styling like fonts, margins, and color palettes. You can also apply themes ephemerally to a single plot. ```r # View current defaults tinyplot(lat ~ long | depth, data = quakes) # Apply a theme (persistent) tinytheme("clean2") tinyplot(lat ~ long | depth, data = quakes, main = "Earthquakes off Fiji", sub = "Clean theme with dynamic margins") tinytheme("dark") tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris) tinytheme("minimal") tinyplot(mpg ~ wt | cyl, data = mtcars) # Customize theme settings tinytheme("bw", fg = "darkblue", font.main = 2, family = "Palatino") tinyplot(mpg ~ wt, data = mtcars, main = "Custom Theme") # Reset to default tinytheme() # Ephemeral theme (applies only to single plot) tinyplot(0:10, theme = "clean", main = "Ephemeral theme") tinyplot(10:0, main = "Back to default") ``` -------------------------------- ### Use shorthand plt() alias and add layers Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Utilizes the plt() shorthand and adds a linear model layer using plt_add(). ```r plt( Sepal.Length ~ Petal.Length | Species, data = iris, palette = "dark", pch = 16, grid = TRUE, frame = FALSE ) plt_add(type = "lm") ``` -------------------------------- ### Query and Set Graphical Parameters Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Manages graphical parameters using `tpar()`, extending base R's `par()`. Allows querying and setting parameters like axis label orientation, point styles, and facet backgrounds. ```r # Query current parameters tpar("las", "pch", "facet.bg", "grid") # Set parameters (returns previous values) op = tpar( las = 1, # horizontal axis labels pch = 16, # filled circles facet.bg = "grey90", facet.cex = 1.2, grid = TRUE ) tinyplot(mpg ~ wt, data = mtcars, facet = ~am) # Reset to original tpar(op) ``` -------------------------------- ### Create Density Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Plots kernel density estimates using type_density(). Allows for grouping and custom bandwidth selection. ```r # Basic density plot tinyplot(~Sepal.Length, data = iris, type = "density") # Grouped density tinyplot(~Sepal.Length | Species, data = iris, type = "density") # Filled densities tinyplot(~Sepal.Length | Species, data = iris, type = "density", fill = "by") # Custom bandwidth method tinyplot( ~Sepal.Length | Species, data = iris, type = type_density(bw = "SJ", joint.bw = "none"), main = "Individual bandwidths per group" ) ``` -------------------------------- ### Create Ridge Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates ridge plots for visualizing distributions across groups using type_ridge(). Recommended to use with tinytheme("ridge"). ```r aq = transform( airquality, Month = factor(month.abb[Month], levels = month.abb[5:9]) ) # Basic ridge plot (recommend using ridge theme) tinytheme("ridge") tinyplot(Month ~ Temp, data = aq, type = "ridge") # Color by y groups tinyplot(Month ~ Temp | Month, data = aq, type = "ridge") # Gradient coloring along x-axis tinyplot(Month ~ Temp | Temp, data = aq, type = "ridge") # Manual gradient without legend tinyplot(Month ~ Temp, data = aq, type = type_ridge(gradient = TRUE)) # Customize scaling and appearance tinyplot( Month ~ Temp, data = aq, type = type_ridge(scale = 1.2, col = "white", gradient = "viridis") ) tinytheme() # reset theme ``` -------------------------------- ### Create QQ Plot Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a Quantile-Quantile (QQ) plot to compare the quantiles of a sample distribution to the quantiles of a theoretical distribution. Useful for assessing normality or other distribution assumptions. ```r tinyplot(~Sepal.Length | Species, data = iris, type = "qq") ``` -------------------------------- ### Load tinyplot library Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Loads the tinyplot package into the current R session, making its functions available for use. ```r library(tinyplot) ``` -------------------------------- ### Control grid appearance with tpar() Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md The `tpar()` function has gained `grid.col`, `grid.lty`, and `grid.lwd` arguments for fine-grained control over the default panel grid when `tinyplot(..., grid = TRUE)` is used. ```R tpar(grid.col = "grey", grid.lty = 2, grid.lwd = 0.5) ``` -------------------------------- ### Generate grouped density plots Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Creates a density plot grouped by species with custom titles and fill aesthetics. ```r plt( ~ Petal.Length | Species, data = iris, type = "density", fill = "by", main = "Distribution of petal lengths", sub = "Grouped by species" ) ``` -------------------------------- ### Create Ribbon Plot with Ymin/Ymax Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a ribbon plot using specified x, ymin, and ymax values. Use this to visualize ranges or confidence intervals. ```r tinyplot(x = x, ymin = y - 1, ymax = y + 1, type = "ribbon") ``` ```r tinyplot(x = x, y = y, ymin = y - 1, ymax = y + 1, type = "ribbon") ``` -------------------------------- ### Use tinyplot() for grouped/faceted density plots Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Grouped and faceted density plots are no longer directly supported via `tinyplot.density()`. Instead, use `tinyplot(..., type = "density")` or `tinyplot(..., type = type_density())` on raw data, passing grouping or facet arguments as needed. ```R tinyplot(..., type = "density") ``` ```R tinyplot(..., type = type_density()) ``` -------------------------------- ### Creating Scatter Plots with type_points() Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates scatter plots, which is the default type for numeric data. ```r # Basic scatter plot tinyplot(Sepal.Width ~ Sepal.Length, data = iris, type = "p") # Grouped scatter with filled points tinyplot( Sepal.Width ~ Sepal.Length | Species, data = iris, type = "p", pch = 19, alpha = 0.7 ) ``` -------------------------------- ### Create Violin Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates violin plots as an alternative to boxplots using type_violin(). Supports orientation flipping and grouping. ```r # Basic violin plot tinyplot(count ~ spray, data = InsectSprays, type = "violin") # Horizontal orientation tinyplot(count ~ spray, data = InsectSprays, type = "violin", flip = TRUE) # Grouped violin with fill tinyplot(len ~ dose | supp, data = ToothGrowth, type = "violin", fill = 0.2) # Customized violin tinyplot( count ~ spray, data = InsectSprays, type = type_violin(trim = TRUE, width = 0.8, joint.bw = "none") ) ``` -------------------------------- ### Control ribbon transparency with type_ribbon() Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md The `ribbon.alpha` argument in `tinyplot()` is deprecated. Use the `alpha` argument within `type_ribbon()` (or equivalents) for controlling ribbon transparency. ```R tinyplot(..., type = type_ribbon(alpha = 0.5)) ``` -------------------------------- ### Creating Line Plots with type_lines() Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates line plots, typically used for time series or sequential data. ```r # Basic line plot tinyplot(AirPassengers, type = "l") # Grouped line plot tinyplot( Temp ~ Day | Month, data = airquality, type = "l", lwd = 2 ) # Both points and lines tinyplot(Temp ~ Day | Month, data = airquality, type = "b") ``` -------------------------------- ### Main Plotting with tinyplot() and plt() Source: https://context7.com/grantmcdermott/tinyplot/llms.txt The primary function for creating various plot types with support for formulas, grouping, and faceting. The plt() function serves as a shorthand alias. ```r library(tinyplot) # Basic scatterplot (drop-in replacement for plot) tinyplot(0:10) # Grouped scatterplot with automatic legend using formula syntax # The | operator specifies the grouping variable tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris) # Equivalent using atomic method with `by` argument with(iris, tinyplot(x = Petal.Length, y = Sepal.Length, by = Species)) # Shorthand alias with customization plt( Sepal.Length ~ Petal.Length | Species, data = iris, pch = 16, # filled points cex = 2, # larger size alpha = 0.5, # transparency palette = "tableau" # color palette ) # Use "by" keyword to vary aesthetics by group tinyplot( Temp ~ Day | Month, data = airquality, pch = "by", # different point characters per group lty = "by", # different line types per group cex = "by" # different sizes per group ) # Bubble plot: pass vector to cex for size mapping tinyplot( Temp ~ Day | Month, data = airquality, pch = 21, cex = airquality$Wind, # map point size to Wind variable bg = 0.3, # filled with transparency col = "black" ) # Faceted plot tinyplot( Temp ~ Day, facet = ~Month, data = airquality, type = "area", main = "Temperatures by month" ) # Facets with grouping combined aq = transform(airquality, Summer = Month %in% c(6, 7, 8)) tinyplot( Temp ~ Day | Summer, facet = ~Month, facet.args = list(nrow = 1), # single row layout data = aq, type = "area", palette = "dark2", frame = FALSE ) # Two-sided formula for fixed grid layout (rows ~ columns) tinyplot( Temp ~ Day, facet = am ~ vs, data = mtcars ) # Add common elements to each facet using `draw` tinyplot( Temp ~ Day, facet = ~Month, data = airquality, draw = abline(h = 75, lty = 2, col = "hotpink") ) # Save plot directly to file tinyplot( Sepal.Length ~ Petal.Length | Species, data = iris, file = "myplot.png", width = 8, height = 6 ) ``` -------------------------------- ### Manage Plot Hooks for Themes Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Preserve and restore plot hooks when applying custom themes to ensure correct rendering. ```r oldhook = getHook("before.plot.new") setHook("before.plot.new", function() par(new = TRUE), action = "append") plot.new() setHook("before.plot.new", oldhook, action = "replace") ``` -------------------------------- ### Independent axis scaling for facets with tinyplot() Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md The `facet.args` argument now includes a `free` sub-argument to independently scale axis limits for individual facets. This provides more control over faceted plot appearance. ```R tinyplot(..., facet.args = list(free = TRUE)) ``` -------------------------------- ### Create Point Range Plot Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a point range plot, displaying a central estimate with upper and lower bounds. Useful for showing uncertainty in estimates. ```r mod = lm(mpg ~ wt * factor(am), mtcars) coefs = data.frame( term = names(coef(mod)), est = coef(mod), lwr = confint(mod)[,1], upr = confint(mod)[,2] ) # Point range tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs, type = "pointrange") ``` -------------------------------- ### Customize Axis Breaks and Labels Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Use yaxb to define manual break points and yaxl to apply formatting functions to axis tick labels. ```r tinyplot((0:10)/10, yaxb = c(.17, .33, .5, .67, .83), yaxl = "%") ``` -------------------------------- ### Create Summary Statistics Plot Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a plot displaying summary statistics (e.g., mean) for a numeric variable grouped by a factor variable. Use `type_summary` with a specified function. ```r tinyplot(Temp ~ Month, data = airquality, type = type_summary(fun = mean)) ``` -------------------------------- ### Create Function Plot Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a plot of a specified mathematical function within given x-axis limits. Use `type_function` with `fun` and `args` arguments. ```r tinyplot(type = type_function(fun = dnorm, args = list(mean = 0, sd = 1)), xlim = c(-4, 4)) ``` -------------------------------- ### Create Bar Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates bar plots for categorical data using type_barplot(). Supports stacking, side-by-side grouping, and aggregation. ```r # Frequency table (one-sided formula) tinyplot(~cyl, data = mtcars, type = "barplot") # Stacked grouped bars (default) tinyplot(~cyl | vs, data = mtcars, type = "barplot") # Side-by-side grouped bars tinyplot(~cyl | vs, data = mtcars, type = "barplot", beside = TRUE, fill = 0.2) # Aggregated values (y ~ x) tinyplot(extra ~ ID | group, facet = "by", data = sleep, type = "barplot", fill = 0.6) # Reorder categories tinyplot(~cyl, data = mtcars, type = "barplot", xlevels = c("8", "6", "4")) # Horizontal bars tinyplot(~cyl | vs, data = mtcars, type = "barplot", flip = TRUE) ``` -------------------------------- ### Create Box-and-Whisker Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates boxplots using the type_boxplot() function or the 'boxplot' type string. Supports grouping and customization of box aesthetics. ```r # Basic boxplot (automatic when x is factor) tinyplot(count ~ spray, data = InsectSprays) # Explicit type specification tinyplot(count ~ spray, data = InsectSprays, type = "boxplot") # Grouped boxplot tinyplot(len ~ dose | supp, data = ToothGrowth, type = "boxplot") # Customized boxplot using type_boxplot() tinyplot( len ~ dose | supp, data = ToothGrowth, lty = 1, type = type_boxplot(boxwex = 0.3, staplewex = 0, outline = FALSE, notch = TRUE) ) # Horizontal boxplot tinyplot(count ~ spray, data = InsectSprays, type = "boxplot", flip = TRUE) ``` -------------------------------- ### Create Dodged Grouped Point Range Plot Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates dodged point range plots for grouped data, allowing comparison across categories while maintaining clarity for overlapping estimates. `fixed.dodge = TRUE` ensures consistent spacing. ```r tinyplot( estimate ~ term | model, ymin = conf.low, ymax = conf.high, data = models_df, type = type_pointrange(dodge = 0.1, fixed.dodge = TRUE) ) tinytheme() ``` -------------------------------- ### Create Ribbon and Area Plots Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Creates filled regions between y-values or from zero using type_ribbon() or type_area(). ```r x = 1:100 / 10 y = sin(x) ``` -------------------------------- ### Create faceted scatterplots Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Generates a faceted scatterplot with a continuous gradient legend. ```r plt( Sepal.Length ~ Petal.Length | Sepal.Length, data = iris, facet = ~Species, pch = 19, main = "Faceted flowers", sub = "Brought to you by tinyplot" ) ``` -------------------------------- ### Flip plot orientation with tinyplot() Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Use the `flip` argument to easily swap the x and y axes orientation in any plot type. This is useful for adapting plots to different display needs. ```R tinyplot(~Sepal.Length | Species, data = iris, type = "density", flip = TRUE) ``` -------------------------------- ### Format axis labels with tinylabel Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Uses convenience keywords or custom functions to format axis tick labels and breaks. ```r # Convenience keywords for xaxl/yaxl tinyplot(1:10 / 10, yaxl = "%") # percent: "10%", "20%", ... tinyplot(1e4:1e5, yaxl = ",") # comma: "10,000", "20,000", ... tinyplot(1:10 * 1000, yaxl = "$") # dollar: "$1,000", "$2,000", ... # Log-scale with log labels tinyplot(x = 10^(0:10), y = 0:10, type = "b", log = "x", xaxl = "log") # Custom break points + labels tinyplot(x = 10^(0:10), y = 0:10, type = "b", log = "x", xaxl = "log", xaxb = 10^c(1, 3, 5, 7, 9)) # Custom formatting function dat = data.frame( date = seq(as.Date("2000/1/1"), by = "month", length.out = 12), value = cumsum(rnorm(12)) ) tinyplot(value ~ date, data = dat, xaxl = function(x) format(x, "%b %Y")) # Direct use of tinylabel tinylabel(1e4, ",") # "10,000" tinylabel(0.25, "%") # "25%" tinylabel(1e6, "$") # "$1,000,000" ``` -------------------------------- ### Create Error Bars for Coefficients Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates error bars to visualize estimates and their confidence intervals, commonly used for regression coefficients. Requires data with term, estimate, lower, and upper bounds. ```r mod = lm(mpg ~ wt * factor(am), mtcars) coefs = data.frame( term = names(coef(mod)), est = coef(mod), lwr = confint(mod)[,1], upr = confint(mod)[,2] ) # Error bars tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs, type = "errorbar") ``` -------------------------------- ### Customize plot legends Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Demonstrates positioning, disabling, and detailed configuration of legends in tinyplot. ```r # Default: legend outside on right tinyplot(Temp ~ Day | Month, data = airquality, type = "l") # Position keywords (add "!" for outside placement) tinyplot(Temp ~ Day | Month, data = airquality, type = "l", legend = "topleft") # inside tinyplot(Temp ~ Day | Month, data = airquality, type = "l", legend = "bottom!") # outside bottom # Turn off legend tinyplot(Temp ~ Day | Month, data = airquality, type = "l", legend = FALSE) # Detailed customization via legend() tinyplot( Temp ~ Day | Month, data = airquality, type = "l", legend = legend( "bottom!", title = "Month of Year", bty = "o", horiz = TRUE ) ) # Custom legend labels via labeller tinyplot( Temp ~ Day | Month, data = airquality, legend = list(labeller = toupper) ) ``` -------------------------------- ### Create Horizontal Error Bars with Reference Line Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates horizontal error bars and adds a vertical reference line. Use `flip = TRUE` for horizontal orientation and `tinyplot_add` for reference lines. ```r mod = lm(mpg ~ wt * factor(am), mtcars) coefs = data.frame( term = names(coef(mod)), est = coef(mod), lwr = confint(mod)[,1], upr = confint(mod)[,2] ) # Horizontal orientation with reference line tinytheme("classic") tinyplot(est ~ term, ymin = lwr, ymax = upr, data = coefs, type = "errorbar", flip = TRUE) tinyplot_add(type = "vline", lty = 2) ``` -------------------------------- ### Customizing Plot Type with Functional Arguments Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Illustrates the recommended method for passing type-specific arguments by embedding them within the functional type call, such as type_hist(breaks = 30). This is preferred over passing arguments at the top level of tinyplot(). ```r tinyplot(Nile, type = type_hist(breaks = 30)) ``` -------------------------------- ### Reset plot theme Source: https://github.com/grantmcdermott/tinyplot/blob/main/README.md Resets the current theme to default settings. ```r # reset the theme tinytheme() ``` -------------------------------- ### Faceting with Complex Formulas in Tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Handles complex facet arrangements, including interactions and multivariate formulas, ensuring all panels are plotted correctly even if some combinations are missing. ```R tinyplot(mpg ~ wt, data = mtcars, facet = am + vs ~ gear) ``` -------------------------------- ### Fit Linear Models Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Plots linear regression lines with confidence intervals using type_lm(). ```r # Basic linear fit with confidence interval tinyplot(Sepal.Width ~ Petal.Width, data = iris, type = "lm") # Grouped fits (demonstrates Simpson's paradox) tinyplot(Sepal.Width ~ Petal.Width | Species, data = iris, type = "lm") tinyplot_add(type = "p") # add points # Adjust confidence level tinyplot(Sepal.Width ~ Petal.Width, data = iris, type = type_lm(level = 0.8)) # Without confidence interval tinyplot(Sepal.Width ~ Petal.Width, data = iris, type = type_lm(se = FALSE)) ``` -------------------------------- ### Create Spineplot for Factor Variables Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates a spineplot, which displays the conditional distribution of a numeric variable across categories of one or more factor variables. Useful for exploring relationships between categorical and continuous data. ```r tinyplot(Survived ~ Class | Sex, data = as.data.frame(Titanic), type = "spineplot") ``` -------------------------------- ### Add custom drawing functions with tinyplot() Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md The `draw` argument allows passing arbitrary drawing functions that are evaluated before the main plotting elements. This is useful for adding common annotations like text or threshold lines across facets. ```R tinyplot(..., draw = list(function(p) { p + geom_vline(xintercept = 0) })) ``` -------------------------------- ### Customize legend settings Source: https://github.com/grantmcdermott/tinyplot/blob/main/.CLAUDE.md Use this snippet within a type's data function to set default legend arguments if they are not already defined. ```r settings$legend_args[["pch"]] = settings$legend_args[["pch"]] %||% 22 settings$legend_args[["pt.cex"]] = settings$legend_args[["pt.cex"]] %||% 3.5 ``` -------------------------------- ### Plotting numeric ~ character variables Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Plots of the form `plt(numeric ~ character)` now work correctly by automatically coercing the character variable to a factor. ```R plt(numeric_var ~ character_var) ``` -------------------------------- ### Fit LOESS Smoothing Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Performs local polynomial regression fitting using type_loess(). ```r # Basic loess fit tinyplot(Sepal.Width ~ Petal.Width, data = iris, type = "loess") # Grouped loess with points tinyplot(Sepal.Width ~ Petal.Width | Species, data = iris, type = "p") plt_add(type = "loess") ``` -------------------------------- ### Create Dodged Ribbons for Overlapping Groups Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Generates dodged ribbon plots to visualize ranges for different groups that might overlap. Requires data in a data frame format with explicit range columns. ```r dat = data.frame( x = rep(c("Before", "After"), each = 2), grp = rep(c("A", "B"), 2), y = c(10, 10.5, 15, 15.3), lwr = c(8, 8.5, 13, 13.3), upr = c(12, 12.5, 17, 17.3) ) tinyplot( y ~ x | grp, data = dat, ymin = lwr, ymax = upr, type = type_ribbon(dodge = 0.1) ) ``` -------------------------------- ### Fine-grained control for faceted histograms Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md The `type_histogram()` function now includes `free.breaks` and `drop.zeros` arguments for fine-grained control over free axis scaling in faceted histograms. ```R type_histogram(free.breaks = TRUE, drop.zeros = FALSE) ``` -------------------------------- ### Plotting Logarithmic Transformation of X vs X in Tinyplot Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md Avoids triggering an inadvertent legend when plotting a function transformation of x against x itself, such as `log(x) ~ x`. ```R tinyplot(log(x) ~ x) ``` -------------------------------- ### Layering Plot Elements with tinyplot_add() Source: https://context7.com/grantmcdermott/tinyplot/llms.txt Adds additional layers to an existing tinyplot, inheriting arguments from the previous call. ```r # Create base scatter plot tinyplot(Sepal.Width ~ Sepal.Length | Species, facet = ~Species, data = iris) # Add linear model fit layer tinyplot_add(type = "lm") # Equivalent shorthand plt_add(type = "lm") # Add multiple layers sequentially tinyplot(Sepal.Width ~ Petal.Width | Species, data = iris, type = "p") plt_add(type = "lm") # add regression lines plt_add(type = "loess") # add loess smoothing # Example with density plots comparing bandwidth methods tinyplot(~Sepal.Length | Species, data = iris, ylim = c(0, 1.25), type = "density") tinyplot_add(joint.bw = "full", lty = 2) tinyplot_add(joint.bw = "none", lty = 3) legend("topright", c("Mean", "Full", "None"), lty = 1:3, bty = "n") ``` -------------------------------- ### Customize joint bandwidth for density plots Source: https://github.com/grantmcdermott/tinyplot/blob/main/NEWS.md For grouped density plots, the joint smoothing bandwidth calculation has changed. Use the `type_density(joint.bw =