This visualization plots the extent to which people consider airplane behaviors rude. Most people considered it rude to bring an unruly child and to wake up a neighbor to walk around, but other behaviors were considered not rude by the majority of the respondents.
figure_1 %>%
ggplot(aes(x= type, y = n, fill = judgment)) +
geom_bar(stat = "identity") +
coord_flip() +
colorblindr::scale_fill_OkabeIto(name = "Judgment") +
theme_minimal()
This is my first attempt to plot responses to airplane etiquette questions. It holds all of the information that I need but it takes more time than necessary to figure out which judgment is the rudest. For the next draft, I wanted to order the judgments from rudest to least rude, fix the x-axis scale from n to percents because each condition has a different n due to missing data, and make a “divergent” bar graph, which centers positive and negative judgments at zero.
figure_1 %>%
ggplot(aes(x = perc, y = fct_reorder(type, perc), fill = judgment)) +
geom_bar(stat="identity",position="identity", width = .8) +
colorblindr::scale_fill_OkabeIto(name = "Judgment")+
scale_x_continuous(breaks = pretty(figure_1$perc),
labels = paste0(abs(pretty(figure_1$perc))*100, "%"))+
theme_minimal() +
labs(x = NULL,
y = NULL)
A divergent bar graph with more than two categories is difficult to do and I had never done one before, so I started with this graph, collapsing down somewhat rude and very rude judgments in a category called “rude.” For the next figure, I made a divergent graph with three categorizes, used break lines to make the labels clearer, and used geom_vline()
to separate rude from not rude judgments.
ggplot() +
geom_bar(data = figure_1_no, aes(x = perc, y = fct_reorder(type, perc), fill = judgment),
stat="identity",position="stack", width = .8, alpha = .8) +
geom_bar(data = figure_1_yes, aes(x = perc, y = fct_reorder(type,perc), fill = forcats::fct_rev(judgment)),
stat = "identity", position = "stack", width = .8, alpha = .8) +
geom_vline(xintercept = 0, color = "black", linetype = "dashed") +
colorblindr::scale_fill_OkabeIto(name = "")+
scale_x_continuous(breaks = pretty(figure_1$perc),
limits = c(-.9, .9),
labels = paste0(abs(pretty(figure_1$perc*100)), "%"))+
theme_minimal() +
labs(x = NULL,
y = NULL,
title = "What's the rudest airplane behavior?") +
theme(legend.position = "bottom",
legend.direction = "horizontal",
plot.title.position = "plot")
In order to have three judgment categories (including somewhat rude), I had to use two different geom_bar()
lines, one for the rude judgments and one for the not rude judgments. For my final version, I added numbers directly to the plot so that you don’t have to look down at the axis to know how many people thought each judgment was rude. This was pretty tricky because some of the judgments had small bars so the labels needed to be plotted off of the graph.
ggplot() +
geom_bar(data = figure_1_no,
aes(x = perc, y = fct_reorder(type, perc),
fill = judgment),
stat="identity", position="stack",
width = .8, alpha = .8) +
geom_bar(data = figure_1_yes,
aes(x = perc, y = fct_reorder(type,perc),
fill = forcats::fct_rev(judgment)),
stat = "identity", position = "stack",
width = .8, alpha = .8) +
geom_vline(xintercept = 0, color = "black", linetype = "dashed")+
geom_text(data = figure_1_no,
aes(x=perc/2, y = type,
label = paste0(abs(round(perc*100)),"%")),
size = 4) +
geom_text(data = very_rude,
aes(x = ifelse(perc > .05,
somewhat_rude$perc + perc/2,
somewhat_rude$perc + perc),
y = type, label = paste0(round(perc*100), "%")),
size = 4, hjust = ifelse(very_rude$perc > .05, .4, -.2)) +
geom_text(data = somewhat_rude,
aes(x=perc/2, y = type,label = paste0(round(perc*100), "%")),
size = 4) +
colorblindr::scale_fill_OkabeIto(name = "")+
scale_x_continuous(limits = c(-.85, .85),
labels = NULL)+
theme_minimal(base_size = 12) +
labs(x = NULL,
y = NULL,
title = "What's the rudest airplane behavior?") +
theme_minimal()+
theme(legend.position = "bottom",
legend.direction = "horizontal",
plot.title.position = "plot",
axis.text.y = element_text(face = c("bold", "plain", "bold", "plain", 'bold', 'plain', 'bold', 'plain', 'bold')))