Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/ggslopegraph2.R
Creates a "slopegraph" as conceptualized by Edward Tufte. Slopegraphs are minimalist and efficient presentations of your data that can simultaneously convey the relative rankings, the actual numeric values, and the changes and directionality of the data over time. Takes a dataframe as input, with three named columns being used to draw the plot. Makes the required adjustments to the ggplot2 parameters and returns the plot.
1 2 3 4 5 6 | ggslopegraph2(dataframe, times, measurement, grouping, title = "",
subtitle = "", caption = "", xtextsize = 12, ytextsize = 3,
titletextsize = 14, subtitletextsize = 10, captiontextsize = 8,
linethickness = 1, linecolor = "ByGroup", datatextsize = 2.5,
datatextfamily = "sans", datatextface = "plain",
labeltextfamily = "sans", labeltextface = "bold")
|
dataframe |
a dataframe or an object that can be coerced to a dataframe.
Basic error checking is performed, to include ensuring that the named columns
exist in the dataframe. See the |
times |
a column inside the dataframe that will be plotted on the x axis.
Traditionally this is some measure of time. The function accepts a column of class
ordered, factor or character. NOTE if your variable is currently a "date" class
you must convert before using the function with |
measurement |
a column inside the dataframe that will be plotted on the y axis. Traditionally this is some measure such as a percentage. Currently the function accepts a column of type integer or numeric. The slopegraph will be most effective when the measurements are not too disparate. |
grouping |
a column inside the dataframe that will be used to group and distinguish measurements. |
title |
Optionally the title to be displayed. title = NULL will remove it entirely. title = "" will provide an empty title but retain the spacing. |
subtitle |
Optionally the sub-title to be displayed. subtitle = NULL will remove it entirely. subtitle = "" will provide an empty subtitle but retain the spacing. |
caption |
Optionally the caption to be displayed. caption = NULL will remove it entirely. caption = "" will provide an empty title but retain the spacing. |
xtextsize |
Optionally the font size for the X axis labels to be displayed. xtextsize = 12 is the default must be a numeric. Note that X & Y axis text are on different scales |
ytextsize |
Optionally the font size for the Y axis labels to be displayed. ytextsize = 3 is the default must be a numeric. Note that X & Y axis text are on different scales |
titletextsize |
Optionally the font size for the title to be displayed. titletextsize = 14 is the default must be a numeric. |
subtitletextsize |
Optionally the font size for the subtitle to be displayed. subtitletextsize = 10 is the default must be a numeric. |
captiontextsize |
Optionally the font size for the caption to be displayed. captiontextsize = 8 is the default must be a numeric. |
linethickness |
Optionally the thickness of the plotted lines. linethickness = 1 is the default must be a numeric. |
linecolor |
Optionally the color of the plotted lines. By default it will use
the ggplot2 color palette for coloring by |
datatextsize |
Optionally the font size of the plotted data points. datatextsize = 2.5 is the default must be a numeric. |
datatextfamily |
Optionally the font family of the plotted data points. datatextfamily = "sans" is the default. |
datatextface |
Optionally the font face of the plotted data points. datatextface = "plain" is the default. |
labeltextfamily |
Optionally the font family of the grouping labels. labeltextfamily = "sans" is the default. |
labeltextface |
Optionally the font face of the grouping labels. labeltextface = "bold" is the default. |
formatting changes as well as major changes to linecolor
A ggplot
object.
Chuck Powell
For a observation-by-time data frame interface, see ggslopegraph
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # basic graph
ggslopegraph2(cancer2, Year, Survival, Type,
title = "Estimates of Percent Survival Rates")
# with further customization
ggslopegraph2(cancer2, Year, Survival, Type,
title = "Estimates of Percent Survival Rates",
linecolor = "black",
linethickness = 1,
subtitle = NULL,
caption = NULL)
# demonstrating linecolor recyclng
ggslopegraph2(cancer2, Year, Survival, Type,
title = "Estimates of Percent Survival Rates",
subtitle = "Based on: Edward Tufte, Beautiful Evidence, 174, 176.",
caption = "https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk",
linecolor = c("black", "red", "grey"),
linethickness = .5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.