### Install ggblanket Package Source: https://github.com/davidhodge931/ggblanket/blob/main/README.md This code snippet demonstrates how to install the ggblanket package from CRAN. It requires an active internet connection to download the package and its dependencies. ```r install.packages("ggblanket") ``` -------------------------------- ### Create Density Plots Source: https://context7.com/davidhodge931/ggblanket/llms.txt Generates density plots using `gg_density` to visualize the distribution of a continuous variable. The example demonstrates mapping a variable to the x-axis and using color for grouping. Arguments for transparency (`alpha`), x-axis label, and y-axis label are also shown. ```r # Density plot with fill penguins |> gg_density( x = body_mass_g, col = species, alpha = 0.5, x_label = "Body mass (g)", y_label = "Density" ) ``` -------------------------------- ### Create Histogram with ggblanket Source: https://github.com/davidhodge931/ggblanket/blob/main/README.md This example shows how to use the gg_histogram function from the ggblanket package to create a histogram. It requires the ggblanket and palmerpenguins libraries, and sets the ggblanket theme. The input is a data frame (penguins) with specified x and color aesthetics. ```r library(ggblanket) library(palmerpenguins) set_blanket() penguins %>% gg_histogram( x = flipper_length_mm, col = species, ) ``` -------------------------------- ### Create Column Charts Source: https://context7.com/davidhodge931/ggblanket/llms.txt Generates column charts using `gg_col` for pre-calculated values. This differs from `gg_bar` which uses `stat='count'`. The example shows how to group data, summarize it to calculate mean mass, and then create a column chart with aesthetic mappings for x, y, and color, along with positioning and labeling options. ```r # Column chart with pre-summarized data penguins |> group_by(species, sex) |> summarise(mean_mass = mean(body_mass_g, na.rm = TRUE), .groups = "drop") |> gg_col( x = species, y = mean_mass, col = sex, position = "dodge", y_label = "Average body mass (g)", title = "Average Body Mass by Species and Sex" ) ``` -------------------------------- ### Create Violin Plots Source: https://context7.com/davidhodge931/ggblanket/llms.txt Generates violin plots using `gg_violin`, which combine density curves with box plot elements. The example maps a categorical variable to the x-axis, a continuous variable to the y-axis, and uses color for grouping. Custom color palettes can be applied using `col_palette`. ```r # Violin plot penguins |> gg_violin( x = species, y = flipper_length_mm, col = species, y_label = "Flipper length (mm)", col_palette = c("#0095A8FF", "#FFA600FF", "#003F5CFF") ) ``` -------------------------------- ### Apply Light and Dark Mode Themes Source: https://context7.com/davidhodge931/ggblanket/llms.txt Demonstrates the use of `light_mode_r()` and `dark_mode_r()` theme families for applying pre-configured light and dark themes to plots. These themes include variants for legend positioning (r=right, t=top, b=bottom). Custom theme configurations with specific parameters like `base_size` and `panel_grid_colour` are also supported. ```r # Light mode with legend on right (default) penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species, theme = light_mode_r() ) # Dark mode with legend on top penguins |> gg_histogram( x = flipper_length_mm, col = species, theme = dark_mode_t() ) # Custom theme configuration penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species, theme = light_mode_b( base_size = 14, base_family = "sans", panel_grid_colour = "#E5E5E5" ) ) ``` -------------------------------- ### Create Histogram Plots with gg_histogram() in R Source: https://context7.com/davidhodge931/ggblanket/llms.txt The `gg_histogram()` function in R creates histogram visualizations with automatic bin calculation and supports grouping by color and faceting. It accepts data frames and aesthetic mappings for x, color, and facet. Customization includes bin count, position (e.g., 'stack'), and labels. Dependencies include `ggblanket` and `dplyr`. ```r library(dplyr) set_blanket() # Histogram with color grouping and custom bins penguins |> gg_histogram( x = flipper_length_mm, col = species, bins = 50, facet = sex, x_label = "Flipper length (mm)", y_label = "Count", title = "Distribution of Penguin Flipper Lengths" ) # Histogram with stacked position penguins |> gg_histogram( x = body_mass_g, col = island, position = "stack", bins = 30, alpha = 0.8 ) ``` -------------------------------- ### Use Predefined Color Palettes Source: https://context7.com/davidhodge931/ggblanket/llms.txt Demonstrates how to use predefined color palettes like `jumble` and individual colors for plot theming. `scales::show_col()` is used to display the colors in a palette. The `set_blanket()` function can be used to apply a default color palette and individual colors to subsequent plots. ```r # Using the jumble palette (color-blind safe) scales::show_col(jumble) # Output: c("#0095A8FF", "#FFA600FF", "#003F5CFF", "#DA3C39FF", "#EC9ECBFF", "#67609CFF") # Using individual colors scales::show_col(c(blue, grey, teal, orange, navy, red, pink, purple)) # Apply palette to plot set_blanket( col_palette_d = jumble, colour = blue ) penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species ) ``` -------------------------------- ### Advanced Customization of Plots Source: https://context7.com/davidhodge931/ggblanket/llms.txt Illustrates advanced plot customization using prefixed arguments in `gg_point`. This includes setting facets (`facet`, `facet2`, `facet_layout`, `facet_scales`), controlling axes breaks and expansions (`x_breaks`, `y_breaks`, `x_expand`), defining axis limits (`y_limits_include`), and customizing color scales (`col_steps`, `col_breaks_n`, `col_palette`, `col_label`). Labels and titles for the plot can also be set. ```r # Complex plot with multiple customizations penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = bill_length_mm, facet = species, facet2 = sex, facet_layout = "grid", facet_scales = "free", x_breaks = breaks_width(10), y_breaks = breaks_extended(n = 6), x_expand = expansion(mult = 0.05), y_limits_include = c(2000, 7000), col_steps = TRUE, col_breaks_n = 5, col_palette = viridisLite::viridis(20), col_label = "Bill length (mm)", x_label = "Flipper length (mm)", y_label = "Body mass (g)", title = "Penguin Morphometrics", subtitle = "Relationship between flipper length and body mass", caption = "Data: Palmer Penguins", size = 2, alpha = 0.7 ) ``` -------------------------------- ### Configure Global Plot Styling with set_blanket() in R Source: https://context7.com/davidhodge931/ggblanket/llms.txt The `set_blanket()` function in R configures global defaults for subsequent ggblanket plots, including themes, colors, palettes, and geom defaults. It allows for custom color palettes and label formatting. Dependencies include `ggblanket`, `ggplot2`, and `palmerpenguins`. Input is typically data for plotting, and output is the configured plotting environment. ```r library(ggblanket) library(ggplot2) library(palmerpenguins) # Configure dark mode with custom color palette set_blanket( theme = dark_mode_r(), colour = "#E7298AFF", col_palette_d = c("#1B9E77FF", "#D95F02FF", "#7570b3FF", "#E7298AFF", "#66A61EFF", "#E6AB02FF", "#A6761DFF", "#666666FF"), col_palette_c = viridisLite::mako(n = 9, direction = -1), linewidth = 0.66, label_case = snakecase::to_sentence_case ) # All plots now use these defaults penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species ) ``` -------------------------------- ### Create Box Plots Source: https://context7.com/davidhodge931/ggblanket/llms.txt Generates box plots using `gg_boxplot` to compare distributions across categories. This function supports aesthetic mappings for x, y, and color, along with arguments for position adjustment (`position`), width, y-axis label, and plot title. It's ideal for visualizing median, quartiles, and outliers. ```r # Box plot with color grouping penguins |> gg_boxplot( x = species, y = body_mass_g, col = sex, position = "dodge", width = 0.5, y_label = "Body mass (g)", title = "Body Mass by Species and Sex" ) ``` -------------------------------- ### Create Scatter Plots with gg_point() in R Source: https://context7.com/davidhodge931/ggblanket/llms.txt The `gg_point()` function in R generates scatter plots to visualize relationships between two continuous variables. It supports aesthetic mappings for x, y, and color, as well as faceting for subgroup analysis. Customization includes plot labels, title, size, alpha transparency, and symmetric scale handling. Dependencies: `ggblanket`. ```r # Scatter plot with color and faceting penguins |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species, facet = island, facet_scales = "free", x_label = "Flipper length (mm)", y_label = "Body mass (g)", title = "Penguin Body Mass vs Flipper Length", size = 3, alpha = 0.7 ) # With symmetric scales and custom limits penguins |> gg_point( x = bill_length_mm, y = bill_depth_mm, col = species, x_limits_include = 0, y_limits_include = 0, x_symmetric = TRUE, y_symmetric = TRUE ) ``` -------------------------------- ### Create Line Plots with gg_line() in R Source: https://context7.com/davidhodge931/ggblanket/llms.txt The `gg_line()` function in R generates line plots, suitable for time series or ordered continuous data. It maps variables to x and y aesthetics and supports color grouping for multiple lines, as well as faceting for separate plots. Customization includes line width, labels, title, and scale limits. Dependencies: `ggblanket`, `ggplot2`, `tidyr`. ```r library(ggplot2) set_blanket() # Time series line plot economics |> gg_line( x = date, y = unemploy, y_limits_include = 0, y_label = "Unemployment (thousands)", x_label = "Date", title = "US Unemployment Over Time", linewidth = 1 ) # Multiple lines with color grouping economics_long <- economics |> tidyr::pivot_longer(cols = c(unemploy, pop), names_to = "metric", values_to = "value") economics_long |> gg_line( x = date, y = value, col = metric, facet = metric, facet_scales = "free_y", facet_ncol = 1 ) ``` -------------------------------- ### Create Custom Density 2D Plot Source: https://context7.com/davidhodge931/ggblanket/llms.txt Creates a 2D density plot using gg_blanket, specifying the geom and stat. Aesthetic mappings for x, y, and color are defined, with a special mapping for color based on the level of the density. This plot is useful for visualizing the joint distribution of two continuous variables. ```r penguins |> gg_blanket( geom = "density_2d", stat = "density_2d", x = flipper_length_mm, y = body_mass_g, col = species, mapping = aes(color = after_stat(level)) ) ``` -------------------------------- ### Create Bar Charts with gg_bar() in R Source: https://context7.com/davidhodge931/ggblanket/llms.txt The `gg_bar()` function in R creates bar charts, typically for categorical data, using count statistics. It supports vertical or horizontal orientation and allows grouping by color, with options for 'stack' or 'dodge' positions. Customization includes bar width, labels, title, and color palettes. Dependencies: `ggblanket`. ```r # Simple bar chart penguins |> gg_bar( y = species, width = 0.75, y_label = "Species", x_label = "Count" ) # Stacked bar chart with color grouping penguins |> gg_bar( y = island, col = species, position = "stack", width = 0.8, title = "Penguin Species Distribution by Island" ) # Dodged bar chart penguins |> gg_bar( y = species, col = sex, position = "dodge", col_palette = c("#0095A8FF", "#FFA600FF") ) ``` -------------------------------- ### Create Violin Plot with Custom Geoms Source: https://context7.com/davidhodge931/ggblanket/llms.txt Generates a violin plot using gg_blanket, specifying geom, stat, position, and aesthetic mappings. Custom labels and a title can also be set. This function is useful for visualizing the distribution of a continuous variable across different categories. ```r penguins |> gg_blanket( geom = "violin", stat = "ydensity", position = "dodge", x = species, y = body_mass_g, col = sex, x_label = "Species", y_label = "Body mass (g)", title = "Body Mass Distribution by Species and Sex" ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.