Title: | Product Plots for R |
---|---|
Description: | Framework for visualising tables of counts, proportions and probabilities. The framework is called product plots, alluding to the computation of area as a product of height and width, and the statistical concept of generating a joint distribution from the product of conditional and marginal distributions. The framework, with extensions, is sufficient to encompass over 20 visualisations previously described in fields of statistical graphics and 'infovis', including bar charts, mosaic plots, 'treemaps', equal area plots and fluctuation diagrams. |
Authors: | Hadley Wickham [aut, cre], Heike Hofmann [aut] |
Maintainer: | Hadley Wickham <[email protected]> |
License: | GPL-2 |
Version: | 0.1.2 |
Built: | 2024-10-30 06:41:51 UTC |
Source: | https://github.com/hadley/productplots |
Template for a double decker plot. A double decker plot is composed of a sequence of spines in the same direction, with the final spine in the opposite direction.
ddecker(direction = "h")
ddecker(direction = "h")
direction |
direction of first split |
Returns NA
if no columns at any level.
find_col_level(df)
find_col_level(df)
df |
data frame of rectangle positions |
Returns NA
if no rows at any level.
find_row_level(df)
find_row_level(df)
df |
data frame of rectangle positions |
Fluctation partitioning.
fluct(data, bounds, offset = 0.05, max = NULL)
fluct(data, bounds, offset = 0.05, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Template for a fluctuation diagram.
flucts(direction = "h")
flucts(direction = "h")
direction |
direction of first split |
The data is a small sample of variables related to happiness from the general social survey (GSS). The GSS is a yearly cross-sectional survey of Americans, run from 1976. We combine data for 25 years to yield 51,020 observations, and of the over 5,000 variables, we select nine related to happiness:
data(happy)
data(happy)
A data frame with 51020 rows and 10 variables
age. age in years: 18–89.
degree. highest education: lt high school, high school, junior college, bachelor, graduate.
finrela. relative financial status: far above, above average, average, below average, far below.
happy. happiness: very happy, pretty happy, not too happy.
health. health: excellent, good, fair, poor.
marital. marital status: married, never married, divorced, widowed, separated.
sex. sex: female, male.
wtsall. probability weight. 0.43–6
Horizontal bar partition: width constant, height varies.
hbar(data, bounds, offset = 0.02, max = NULL)
hbar(data, bounds, offset = 0.02, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Horizontal spine partition: height constant, width varies.
hspine(data, bounds, offset = 0.01, max = NULL)
hspine(data, bounds, offset = 0.01, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Template for a mosaic plot. A mosaic plot is composed of spines in alternating directions.
mosaic(direction = "v")
mosaic(direction = "v")
direction |
direction of first split |
Template for a nested barchart. A nested bar is just a sequence of bars in the same direction.
nested(direction = "h")
nested(direction = "h")
direction |
direction of first split |
Create a product plot
prodplot( data, formula, divider = mosaic(), cascade = 0, scale_max = TRUE, na.rm = FALSE, levels = -1L, ... )
prodplot( data, formula, divider = mosaic(), cascade = 0, scale_max = TRUE, na.rm = FALSE, levels = -1L, ... )
data |
input data frame |
formula |
formula specifying display of plot |
divider |
divider function |
cascade |
cascading amount, per nested layer |
scale_max |
Logical vector of length 1. If |
na.rm |
Logical vector of length 1 - should missing levels be silently removed? |
levels |
an integer vector specifying which levels to draw. |
... |
other arguments passed on to |
if (require("ggplot2")) { prodplot(happy, ~ happy, "hbar") prodplot(happy, ~ happy, "hspine") prodplot(happy, ~ sex + happy, c("vspine", "hbar")) prodplot(happy, ~ sex + happy, stacked()) prodplot(happy, ~ happy + sex | health, mosaic("h")) + aes(fill=happy) # The levels argument can be used to extract a given level of the plot prodplot(happy, ~ sex + happy, stacked(), level = 1) prodplot(happy, ~ sex + happy, stacked(), level = 2) }
if (require("ggplot2")) { prodplot(happy, ~ happy, "hbar") prodplot(happy, ~ happy, "hspine") prodplot(happy, ~ sex + happy, c("vspine", "hbar")) prodplot(happy, ~ sex + happy, stacked()) prodplot(happy, ~ happy + sex | health, mosaic("h")) + aes(fill=happy) # The levels argument can be used to extract a given level of the plot prodplot(happy, ~ sex + happy, stacked(), level = 1) prodplot(happy, ~ sex + happy, stacked(), level = 2) }
Generate an x-scale for ggplot2 graphics.
scale_x_product(df)
scale_x_product(df)
df |
list of data frame produced by |
Generate a y-scale for ggplot2 graphics.
scale_y_product(df)
scale_y_product(df)
df |
list of data frame produced by |
Spine partition: divide longest dimesion.
spine(data, bounds, offset = 0.01, max = NULL)
spine(data, bounds, offset = 0.01, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Template for a stacked bar chart. A stacked bar chart starts with a bar and then continues with spines in the opposite direction.
stacked(direction = "h")
stacked(direction = "h")
direction |
direction of first split |
Adapated from SquarifiedLayout in http://www.cs.umd.edu/hcil/treemap-history/Treemaps-Java-Algorithms.zip
tile(data, bounds, max = 1)
tile(data, bounds, max = 1)
data |
bounds data frame |
bounds |
bounds of space to partition |
max |
maximum value |
Vertical bar partition: height constant, width varies.
vbar(data, bounds, offset = 0.02, max = NULL)
vbar(data, bounds, offset = 0.02, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Vertical spine partition: width constant, height varies.
vspine(data, bounds, offset = 0.01, max = NULL)
vspine(data, bounds, offset = 0.01, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |