Chapter 12 Single Country Multi-Question Plots
This chapter teaches you how to create a single graph that summarizes responses for multiple variables for a single country.
These types of graphs are especially useful for plotting grid questions. Grid questions use the same stem, but have different endings. Technically, while related, they are all unique questions. Therefore, plotting a set of grid questions on the same graph, is the same thing as plotting multiple question on one graph.
All questions are required to be the same type when using this function. Comparing the responses to different question types is not advised, so the function does not allow for it.
At the end, your code will look like the following:
questions_2_compare <- c("Q210",
"Q211")
questions_labels <- c("Is there corruption?",
"Is the gov't cracking down?")
plot_multiquestions_ind(survey1,
questions_2_compare,
questions_labels,
"Algeria",
.title = "Perceptions of Corruption in Algeria",
.subtitle = "% saying to a medium or large extent",
.caption = "Arab Barometer Wave VI, Survey 1, Algeria")
That code will produce the following graph:
## Warning: `position_dodge()` requires non-overlapping x intervals.
Let’s go!
12.1 Prep Work
There is no calculate_
function7 for this graph. All the computation is done within the plot_multiquestions_ind()
function.
It is useful to do some prep work to keep everything clear.
12.1.1 Question Vector
First create a vector of questions you want to include on your graph. For the example in this chapter we are comparing questions Q210
and Q211
. We put the names of those variables in a vector and save that vector as an object.
Now the variables we want to graph as saved to the object questions_2_compare
in a vector.
12.1.2 Question Labels
The next step is to create a vector of labels for the questions. This is the text that will display on the y-axis. The labels should appear in the same order as they variables they are referring to.
question_labels <- c(
"Is there corruption?", # Text for Q210
"Is the gov't cracking down?" # Text for Q211
)
The object question_labels
represents the text that will serve to label the responses on the graph.
12.2 Plot a Multiquestion Graph for a Single Country
We are now ready to create our graph. The function plot_multiquestions_ind()
is used to create a graph for one country that displays responses to multiple questions. There are three required arguments. They are: .ab
, .questions
, and .question_labels
.
The parameter .ab
is the for Arab Barometer data frame. If there is only one country in the data, the function will automatically know which country it is8. If there is more than one country in the data set, you must use the .country
parameter to specify which country you want to graph.
The .questions
parameter requires a vector (not a list) of questions. This is how the function knows which questions to include on the graph. We created a vector, questions_2_compare
, in the section above.
The .question_labels
parameter requires a vector (not a list) of question labels. The labels must appear in the same order as the questions to appear on the graph correctly. We created a vector, questions_labels
, in the section above.
Time to fill in our function. The data we are using for the example is survey1
. This data frame includes all the countries surveyed during the first round of surveys in Wave VI. We must use the .country
parameter to tell the function which country we wish to plot.
plot_multiquestions_ind(
.ab = survey1,
.questions = questions_2_compare,
.question_labels = question_labels,
.country = "Algeria"
)
## Warning: `position_dodge()` requires non-overlapping x intervals.
Notice there are several missing elements in this graph. Namely, an appropriate title, subtitle, and caption. These three aspects are not included in the list of required arguments, because a graph can be created without them. If you want to use the graph publicly, however, it would be prudent to include them.
The parameters for including a title, subtitle, and caption are the same as they are in any other function: .title
, .subtitle
, and .caption
, respectively. We can fill these in to create our final graph.
plot_multiquestions_ind(
.ab = survey1,
.questions = questions_2_compare,
.question_labels = question_labels,
.country = "Algeria",
.title = "Perceptions of Corruption in Algeria",
.subtitle = "% saying to a medium or large extent",
.caption = "Arab Barometer Wave VI, Survey 1, Algeria"
)
## Warning: `position_dodge()` requires non-overlapping x intervals.
12.3 Extras
12.3.1 Setting Colors
By default, the colors for the graph are randomly selected from ArabBarometer_clr
. To set the colors of the graph, supply a vector of hex codes or named Arab Barometer brand colors to the parameter .clr_choice
.
12.3.2 Data Frame
There is no calculate_
function that accompanies this function. All calculations are done internally. The parameter .return_df
allows the user to see the data frame used to create the graph. Setting .return_df
to TRUE
will cause the function to return a list containing the graph and the data frame. Setting .return_df
to "only"
will cause the function to only return the data frame.
12.3.3 Explict Grid Example
Remember: plotting a set of grid questions requires exactly the same steps as outlined throughout this chapter. There is no difference between plotting 2 (or n) questions that belong to a grid, and 2 (or n) questions that do not.
# Identifying two question from a grid set:
questions_2_compare <- c(
"Q201A_1",
"Q201A_2"
)
# Supplying labels:
question_labels <- c(
"Government",
"Legal system"
)
# Plotting the grid questions:
plot_multiquestions_ind(
.ab = survey1,
.questions = questions_2_compare,
.question_labels = question_labels,
.country = "Algeria",
.title = "How much trust do you have in...",
.subtitle = "% of Algerians saying they have quite a lot or a great deal",
.caption = "Arab Barometer Wave VI, Survey 1, Algeria"
)
## Warning: `position_dodge()` requires non-overlapping x intervals.