Description Usage Arguments Details Note Examples
Apply significance markers onto an existing ggplot2 chart
1 2 | geom_sigmark(tbl_sig, x = "level", y = "pos", group = NULL,
colour = "sign", icon = "full triangle up", size = 5)
|
tbl_sig |
A df object created from tbl_sig functions. |
x |
A quoted character string of the variable from the 'tbl_sig' df charted on the x-axis. Typically this is "level" or "group". |
y |
A quoted character string of the variable from the 'tbl_sig' df charted on the y-axis. Typically this is "pos". |
group |
An optional quoted character string of the variable from the 'tbl_sig' df that is grouped. If needed, it likely needs to be "group". |
colour |
A quoted character string of the variable from the 'tbl_sig' df that applies the subgroup colours. Typically this is "sign". |
icon |
A quoted character string indicating the type of icon to display to denote statistical significance. Default is "full triangle up". |
size |
A numeric value indicating the size of the icon. Default is set to 5. |
This is essentially a wrapper for geom_point
The icon argument accepts one of the following strings:
full triangle up
full triangle down
clear triangle up
clear triangle down
arrow up
arrow down
finger up
finger down
full star
clear star
checkmark
asterisk
heart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | ### Proportions:
colour_vec <- c("NEW ENGLAND" = "#edc951",
"MIDDLE ATLANTIC" = "#eb6841",
"E. NOR. CENTRAL" = "#cc2a36",
"W. NOR. CENTRAL" = "#4f372d",
"SOUTH ATLANTIC" = "#00a0b0",
"E. SOU. CENTRAL" = "#2175d9",
"W. SOU. CENTRAL" = "#00308f",
"MOUNTAIN" = "#e30074",
"PACIFIC" = "#b8d000")
gss_data1 <- dplyr::filter(gss_data, year == "2016",
conlegis %in% c("A GREAT DEAL", "ONLY SOME", "HARDLY ANY"))
my_results <- freq_prop_test(gss_data1, "conlegis", "region", weight = "wtssall")
my_chart_data <- tbl_chart(gss_data1, "conlegis", "region", weight = "wtssall")
my_chart_data$conlegis <- forcats::fct_relevel(my_chart_data$conlegis,
"A GREAT DEAL",
"ONLY SOME",
"HARDLY ANY")
#Trial and error is needed to apply the right values for space_between and space_label
#to get the positioning of the markers correctly.
my_sig_data <- tbl_sig(my_results, "region", space_label = 0.2, space_between = 0.1)
#Setting up a chart
library(ggplot2)
(p <- ggplot() +
geom_col(data = my_chart_data, aes(x = conlegis, fill = region, y = prop)) +
geom_text(data = my_chart_data, aes(x = conlegis,
y = prop,
label = scales::percent(round(prop, 2))),
hjust = -0.2) +
coord_flip() +
facet_wrap(~ region) +
scale_fill_manual(values = colour_vec) + scale_colour_manual(values = colour_vec) +
scale_y_continuous(limits = c(0, 1.5), labels = scales::percent)
)
p + geom_sigmark(my_sig_data)
### Means:
colour_vec <- c("LT HIGH SCHOOL" = "#edc951",
"HIGH SCHOOL" = "#eb6841",
"JUNIOR COLLEGE" = "#cc2a36",
"BACHELOR" = "#4f372d",
"GRADUATE" = "#00a0b0")
gss_data1 <- dplyr::filter(gss_data, year == "2016", coninc > 0)
my_results <- freq_t_test(gss_data1, "coninc", "degree", weight = "wtssall")
my_chart_data <- tbl_chart(gss_data1, "coninc", "degree", weight = "wtssall")
#Trial and error is needed to apply the right values for space_between and space_label
#to get the positioning of the markers correctly.
my_sig_data <- tbl_sig(my_results, "degree", space_label = 5000, space_between = 2100)
#Setting up a chart
library(ggplot2)
(p <- ggplot() +
geom_col(data = my_chart_data, aes(x = degree, y = wtd.mean, fill = degree)) +
geom_text(data = my_chart_data, aes(x = degree,
y = wtd.mean,
label = scales::dollar(round(wtd.mean, 0))),
vjust = -0.2) +
scale_fill_manual(values = colour_vec) + scale_colour_manual(values = colour_vec) +
scale_y_continuous(limits = c(0, 100000), labels = scales::dollar)
)
p + geom_sigmark(my_sig_data, x = "degree")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.