Title: | Visualizing Social Science Data with 'ggplot2' |
---|---|
Description: | A 'ggplot2' extension for implementing parliament charts and several other useful visualizations. |
Authors: | Frederik Tiedemann [aut, cre] |
Maintainer: | Frederik Tiedemann <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.7 |
Built: | 2024-11-03 03:35:10 UTC |
Source: | https://github.com/erocoar/ggpol |
An arc bar diagram that allows for spacing between the individual arc components and spans 180 degrees.
geom_arcbar( mapping = NULL, data = NULL, stat = "arcbar", position = "identity", n = 360, sep = 0.05, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_arcbar( mapping = NULL, data = NULL, geom = "arcbar", position = "identity", n = 360, sep = 0.05, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
geom_arcbar( mapping = NULL, data = NULL, stat = "arcbar", position = "identity", n = 360, sep = 0.05, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_arcbar( mapping = NULL, data = NULL, geom = "arcbar", position = "identity", n = 360, sep = 0.05, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
n |
The number of |
sep |
Separation between the different shares, as a total proportion of pi. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
geom |
The geometric object to use display the data |
geom_arcbar understands the following aesthetics (required aesthetics are in bold):
- **shares** - **r0** - inner radius - **r1** - outer radius - color - fill - linetype - alpha
bt <- data.frame( parties = factor(c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos"), levels = c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos")), seats = c(200, 46, 92, 80, 153, 69, 67, 2), colors = c("black", "blue", "lightblue", "yellow", "red", "purple", "green", "grey"), stringsAsFactors = FALSE) ggplot(bt) + geom_arcbar(aes(shares = seats, r0 = 5, r1 = 10, fill = parties)) + scale_fill_manual(values = bt$colors) + coord_fixed() + theme_void()
bt <- data.frame( parties = factor(c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos"), levels = c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos")), seats = c(200, 46, 92, 80, 153, 69, 67, 2), colors = c("black", "blue", "lightblue", "yellow", "red", "purple", "green", "grey"), stringsAsFactors = FALSE) ggplot(bt) + geom_arcbar(aes(shares = seats, r0 = 5, r1 = 10, fill = parties)) + scale_fill_manual(values = bt$colors) + coord_fixed() + theme_void()
Repelling text for GeomBar.
geom_bartext( mapping = NULL, data = NULL, stat = "identity", position = "identity", parse = FALSE, nudge_x = 0, nudge_y = 0, spacing = 0.003, dir = "v", check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
geom_bartext( mapping = NULL, data = NULL, stat = "identity", position = "identity", parse = FALSE, nudge_x = 0, nudge_y = 0, spacing = 0.003, dir = "v", check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
parse |
If |
nudge_x |
Horizontal and vertical adjustment to nudge labels by. Useful for offsetting text from points, particularly on discrete scales. |
nudge_y |
Horizontal and vertical adjustment to nudge labels by. Useful for offsetting text from points, particularly on discrete scales. |
spacing |
Defaults to 0.003. Minimum spacing between labels in NPC units. |
dir |
Defaults to "v", i.e. vertical repel of overlapping groups of labels. Can alternatively be set to "h" for horizontal repel. |
check_overlap |
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
df <- data.frame(L = rep(LETTERS[1:2], each = 4), l = rep(letters[1:4], 2), val = c(96.5, 1, 2, 0.5, 48, 0.7, 0.3, 51)) ggplot(df, aes(x = L, y = val, fill = l)) + geom_bar(stat = "identity") + geom_bartext(aes(label = paste0(val, "%")), position = position_stack(vjust = 0.5)) + ggtitle("GeomBartext")
df <- data.frame(L = rep(LETTERS[1:2], each = 4), l = rep(letters[1:4], 2), val = c(96.5, 1, 2, 0.5, 48, 0.7, 0.3, 51)) ggplot(df, aes(x = L, y = val, fill = l)) + geom_bar(stat = "identity") + geom_bartext(aes(label = paste0(val, "%")), position = position_stack(vjust = 0.5)) + ggtitle("GeomBartext")
Half boxplot, half scatterplot with customizable jitter.
geom_boxjitter( mapping = NULL, data = NULL, stat = "BoxJitter", position = "dodge", ..., outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, outlier.alpha = NULL, outlier.intersect = FALSE, jitter.colour = NULL, jitter.color = NULL, jitter.fill = NULL, jitter.shape = 19, jitter.size = 1.5, jitter.stroke = 0.5, jitter.alpha = NULL, jitter.position = ggplot2::PositionJitter, jitter.params = list(width = NULL, height = NULL), boxplot.expand = FALSE, notch = FALSE, notchwidth = 0.5, varwidth = FALSE, errorbar.draw = FALSE, errorbar.length = 0.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_boxjitter( mapping = NULL, data = NULL, stat = "BoxJitter", position = "dodge", ..., outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, outlier.alpha = NULL, outlier.intersect = FALSE, jitter.colour = NULL, jitter.color = NULL, jitter.fill = NULL, jitter.shape = 19, jitter.size = 1.5, jitter.stroke = 0.5, jitter.alpha = NULL, jitter.position = ggplot2::PositionJitter, jitter.params = list(width = NULL, height = NULL), boxplot.expand = FALSE, notch = FALSE, notchwidth = 0.5, varwidth = FALSE, errorbar.draw = FALSE, errorbar.length = 0.5, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Use to override the default connection between
|
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
outlier.colour |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.color |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.fill |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.shape |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.size |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.stroke |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.alpha |
Default aesthetics for outliers. Set to In the unlikely event you specify both US and UK spellings of colour, the US spelling will take precedence. Sometimes it can be useful to hide the outliers, for example when overlaying
the raw data points on top of the boxplot. Hiding the outliers can be achieved
by setting |
outlier.intersect |
Defaults to 'FALSE'. If set to 'TRUE', outliers will be part of the jitter-plot (but keeping the given outlier graphical parameters) rather than plotted vertically above / below the whisker lines. |
jitter.colour , jitter.color , jitter.fill , jitter.shape , jitter.size , jitter.stroke , jitter.alpha
|
Default aesthetics for jitter, set to 'NULL' to inherit from the aesthetics used for the box. |
jitter.position |
Position object used for calculating jitter (defaults to 'ggplot2::PositionJitter'). |
jitter.params |
Parameters passed to 'jitter.position' (for 'ggplot2::PositionJitter', this is 'width', 'height' and 'seed'). |
boxplot.expand |
Defaults to 'FALSE'. If set to 'TRUE', the full boxplots will be plotted. |
notch |
If |
notchwidth |
For a notched box plot, width of the notch relative to
the body (defaults to |
varwidth |
If |
errorbar.draw |
Draw horizontal whiskers at the top and bottom (the IQR). Defaults to 'FALSE'. |
errorbar.length |
Length of the horizontal whiskers (errorbar). Defaults to half the width of the half-boxplot, or half the width of the entire boxplot if 'boxplot.expand' is set to 'TRUE'. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
set.seed(221) df <- data.frame(score = rgamma(150, 4, 1), gender = sample(c("M", "F"), 150, replace = TRUE), genotype = factor(sample(1:3, 150, replace = TRUE))) ggplot(df) + geom_boxjitter(aes(x = gender, y = score, fill = genotype), jitter.shape = 21, jitter.color = NA, outlier.color = NA, errorbar.draw = TRUE) + scale_fill_manual(values = c("#CF3721", "#31A9B8", "#258039")) + theme_minimal()
set.seed(221) df <- data.frame(score = rgamma(150, 4, 1), gender = sample(c("M", "F"), 150, replace = TRUE), genotype = factor(sample(1:3, 150, replace = TRUE))) ggplot(df) + geom_boxjitter(aes(x = gender, y = score, fill = genotype), jitter.shape = 21, jitter.color = NA, outlier.color = NA, errorbar.draw = TRUE) + scale_fill_manual(values = c("#CF3721", "#31A9B8", "#258039")) + theme_minimal()
Similar to '[geom_point()]', but allows for full control of the size.
geom_circle( mapping = NULL, data = NULL, stat = "circle", position = "identity", n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_circle( mapping = NULL, data = NULL, geom = "circle", position = "identity", n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
geom_circle( mapping = NULL, data = NULL, stat = "circle", position = "identity", n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_circle( mapping = NULL, data = NULL, geom = "circle", position = "identity", n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
n |
The number of points calculated for the circle polygon, defaults to 360. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
geom |
The geometric object to use display the data |
geom_circle understands the following aesthetics (required aesthetics are in bold):
- **x** - x-coordinate of center - **y** - y-coordinate of center - **r** - radius - color - fill - linetype - alpha
set.seed(22189) df <- data.frame(x = sample(1:10, 3), y = sample(1:10, 3), r = sample(3:4, 3, replace = TRUE)) ggplot(df) + geom_circle(aes(x = x, y = y, r = r, fill = gl(3, 1))) + coord_fixed()
set.seed(22189) df <- data.frame(x = sample(1:10, 3), y = sample(1:10, 3), r = sample(3:4, 3, replace = TRUE)) ggplot(df) + geom_circle(aes(x = x, y = y, r = r, fill = gl(3, 1))) + coord_fixed()
Draws a parliament diagram based on parties' member counts, where each point in the arc represents a single member of parliament. Parties are plotted right-to-left.
geom_parliament( mapping = NULL, data = NULL, stat = "parliament", position = "identity", r0 = 1.5, r1 = 3, n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_parliament( mapping = NULL, data = NULL, geom = "parliament", position = "identity", r0 = 1.5, r1 = 3, n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
geom_parliament( mapping = NULL, data = NULL, stat = "parliament", position = "identity", r0 = 1.5, r1 = 3, n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) stat_parliament( mapping = NULL, data = NULL, geom = "parliament", position = "identity", r0 = 1.5, r1 = 3, n = 360, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
r0 |
Inner radius, defaults to 1.5. |
r1 |
Outer radius, defaults to 3. |
n |
Number of passed to 'StatCircle', defaults to 360. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
geom |
The geometric object to use display the data |
geom_parliament understands the following aesthetics (required aesthetics are in bold): - **seats** - number of seats of the parties - fill - color - linetype - alpha
coordinates of individual MPs
bt <- data.frame( parties = factor(c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos"), levels = c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos")), seats = c(200, 46, 92, 80, 153, 69, 67, 2), colors = c("black", "blue", "lightblue", "yellow", "red","purple", "green", "grey"), stringsAsFactors = FALSE) ggplot(bt) + geom_parliament(aes(seats = seats, fill = parties), color = "black") + scale_fill_manual(values = bt$colors, labels = bt$parties) + coord_fixed() + theme_void()
bt <- data.frame( parties = factor(c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos"), levels = c("CDU", "CSU", "AfD", "FDP", "SPD", "Linke", "Gruene", "Fraktionslos")), seats = c(200, 46, 92, 80, 153, 69, 67, 2), colors = c("black", "blue", "lightblue", "yellow", "red","purple", "green", "grey"), stringsAsFactors = FALSE) ggplot(bt) + geom_parliament(aes(seats = seats, fill = parties), color = "black") + scale_fill_manual(values = bt$colors, labels = bt$parties) + coord_fixed() + theme_void()
This is a version of [ggplot2::geom_rect()] that defaults to spanning the entirety of the y-axis.
geom_tshighlight( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_tshighlight( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_tshighlight understands the following aesthetics (required aesthetics are in bold): - **xmin** - **xmax** - fill - color
ggplot(economics, aes(x = date, y = unemploy)) + geom_line() + geom_tshighlight(aes(xmin = as.Date("01/01/1990", format = "%d/%m/%Y"), xmax = as.Date("01/01/2000", format = "%d/%m/%Y")), alpha = 0.01)
ggplot(economics, aes(x = date, y = unemploy)) + geom_line() + geom_tshighlight(aes(xmin = as.Date("01/01/1990", format = "%d/%m/%Y"), xmax = as.Date("01/01/2000", format = "%d/%m/%Y")), alpha = 0.01)
Plot a confusion matrix.
geom_confmat( mapping = NULL, data = NULL, stat = "confmat", position = "identity", width = NULL, height = NULL, annotate = TRUE, text.perc = FALSE, text.digits = 3, text.alpha = NULL, text.angle = NULL, text.colour = NULL, text.family = NULL, text.fontface = NULL, text.group = NULL, text.hjust = NULL, text.lineheight = NULL, text.size = NULL, text.vjust = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_confmat( mapping = NULL, data = NULL, geom = "tile", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = FALSE, normalize = FALSE, ... )
geom_confmat( mapping = NULL, data = NULL, stat = "confmat", position = "identity", width = NULL, height = NULL, annotate = TRUE, text.perc = FALSE, text.digits = 3, text.alpha = NULL, text.angle = NULL, text.colour = NULL, text.family = NULL, text.fontface = NULL, text.group = NULL, text.hjust = NULL, text.lineheight = NULL, text.size = NULL, text.vjust = NULL, ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_confmat( mapping = NULL, data = NULL, geom = "tile", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = FALSE, normalize = FALSE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
width |
The tile height. |
height |
The tile width. |
annotate |
Boolean indicator for whether to include values as text in each tile. |
text.perc |
Boolean indicator for whether to add '%' to the end of each value. |
text.digits |
Numeric vector equal to length one, indicating the number of digits to display. 'round(x, text.digits)'. |
text.alpha |
Alpha value for the text grobs. |
text.angle |
Angle value for the text grobs. |
text.colour |
Colour of the text grobs. |
text.family |
Font family of the text grobs. |
text.fontface |
Font face of the text grobs. |
text.group |
Groups of the text grobs. |
text.hjust |
Hjust of the text grobs. |
text.lineheight |
Lineheight of the text grobs. |
text.size |
Size of the text grobs. |
text.vjust |
Vjust of the text grobs. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data |
normalize |
Boolean indicator for whether to scale the frequency values. |
x <- sample(LETTERS[seq(4)], 50, replace = TRUE) y <- sample(LETTERS[seq(4)], 50, replace = TRUE) ggplot() + geom_confmat(aes(x = x, y = y), normalize = TRUE, text.perc = TRUE)
x <- sample(LETTERS[seq(4)], 50, replace = TRUE) y <- sample(LETTERS[seq(4)], 50, replace = TRUE) ggplot() + geom_confmat(aes(x = x, y = y), normalize = TRUE, text.perc = TRUE)