library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.4 ✓ purrr 0.3.4
## ✓ tibble 3.1.2 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(devtools)
## Loading required package: usethis
library(ggplot2)
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(tibble)
library(qualtRics)
library(dplyr)
library(ggbeeswarm)
library(patchwork)
First, we are going to rename the datafile from “Study 7 data.csv” to “Experiment2”. The arrow here (<-) is an assignment operator so “Experiment2” is being assigned to “Study_8_data.csv”.The pipe (%>%) basically takes the output of one line and carries it to the input of the next line of code - the renaming of Study 7 data file is being carried onto the line for reading the file. Because the datafile is a csv file, we are going to use the function read_csv().
Experiment2 <- "Study 7 data.csv"
Experiment2 <- read.csv(Experiment2)
We are filtering to include participants who had given their consent with the function filter(). The count() function tells us that 412 participants have given their consent by clicking the consent button. This is the number of participants before the exclusion criteria was applied.
Consented_participants <- Experiment2 %>%
filter(Consent == "1")
count(Consented_participants) # n=412
## n
## 1 412
Just like experiment 1, the authors had planned to exclude participants who did not complete the task, did not take the task seriously, and failed the attention check (i.e., those who had recalled less than 4 headlines correctly during a headline recall task). The function filter() is used to include participants who had successfully completed the task (Finished == “1”), took the task seriously (Serious_check == “1”), and passed the attention check (SC0 >= “4”). The logical operator (==) means exactly equal to. The function count() tells us that there are 400 participants after applying these exclusions. This matched what the authors got.
Experiment2 <- Experiment2 %>%
filter(Finished == "1",
Serious_check == "1",
SC0 >= "4")
count(Experiment2) # n=400
## n
## 1 400
Again like in experiment 1, the two weird names in the the data file is “SC0” which represents recall scores and “FL_12_DO” which represents the different conditions. The function rename() is used to rename these, with old names “SC0” and “FL_10_DO” on the right, and new names “recall_score” and “condition” on the left.
## Renaming variables
Experiment2 <- Experiment2 %>%
rename(recall_score = SC0,
condition = FL_12_DO) #new name = old name
The function summarise() from the tidyverse package creates a new dataframe. In this dataframe, we are including the mean (mean), standard deviation (sd), maximum (max), minimum (min) ages. Doing so shows that the mean age is 34.29, standard deviation of age is 12.97, maximum age is 69, and minimum age is 18.
Experiment2 %>%
summarise(
M.Age = mean(Age), # mean = 33.5
SD = sd(Age), # sd = 12
Max = max(Age), # max = 73
Min = min(Age) # min age = 18
)
## M.Age SD Max Min
## 1 NA 12.03415 73 18
In the datafile, males are represented by “1” while females are represented by “2”. The function filter() is used to include only males or only females, and count() is used to count how many male or female participants the study includes. There are 150 male participants and 248 female participants.
# Males
males <- Experiment2 %>%
filter(Gender == "1")
count(males) # n=150
## n
## 1 150
# Females
females <- Experiment2 %>%
filter(Gender == "2")
count(females) # n=248
## n
## 1 248
Just like Experiment 1, it seems like the two independent variables, format (whether or not there is the qualifier “some” added or not), and conflict (whether headlines are conflicting or not) are placed together in the column “conditions”. This should be separated as the data in the plots is later organized this way. The function separate() helps to turn a single character column into multiple columns. The data (data) being used is “Experiment1”, and we want the column (col) “condition” to be separated into (into = c()) “block”, “number”, “Format” and “Conflict”. The glimpse() function again ensures that the column has successfully been separated.
# Separating condition into separate columns
Experiment2<- separate(data = Experiment2, col = condition, into = c("block", "number", "Format", "Conflict"))
In the authors’ descriptive plots, the 2 conflict conditions of conflict and consistent were renamed to “Conf.” and “Non-Conf.” respectively so we are doing the same using the function recode_factor().
# Renaming levels of conflict
Experiment2$Conflict <- recode_factor(Experiment2$Conflict,
Conflict = "Conf.",
Consistent = "Non-Conf.") # old name = "new name"
We want to change the variable types of the independent variables ‘Conflict’ and ‘Format’ to factors. The symbol “$” is used to select a named list component from the data - here, we are selecting ‘format’ and ‘conflict’ from the Experiment2 data.
# Set IV variable types as factors
Experiment2$Format <- as.factor(Experiment2$Format)
levels(Experiment2$Format)
## [1] "Generic" "Qualified"
Experiment2$Conflict <- as.factor(Experiment2$Conflict)
levels(Experiment2$Conflict)
## [1] "Conf." "Non-Conf."
The dependent variables also have to be set as numeric in order to be created into new variables later on. As there are 6 DVs, each with a range of possible answers and thus different columns, I wanted to use a shortcut to make all of them numeric at once. The function c() within mutate_at() helps do that as it combines arguments. Here, we are changing the variable type of columns 325 top 353 to numeric by specifying “as.numeric”.
# Changing DV from character to numeric
Experiment2 <- Experiment2 %>%
mutate_at(c(325:353), as.numeric)
The mutate() function is used to create the 6 new variables - Nutritional Confusion, Nutritional Backlash, Mistrust of Expertise, Certainty of Knowledge, Development of Knowledge. To get the mean scores of each dependent variable, we are adding the scores and then dividing them by number of columns. For example, there are 6 scores under nutritional confusion thus the scores are divided by 6. To ensure that we have successfully created these new variables, the function select(confusion:development) is used to view the columns of confusion to development as a tibble.
Experiment2 <- Experiment2 %>%
mutate(
confusion = ((Experiment2$NC_1 + Experiment2$NC_2 + Experiment2$NC_3 + Experiment2$NC_4 + Experiment2$NC_5 + Experiment2$NC_6)/6),
backlash = ((Experiment2$NBS_1 + Experiment2$NBS_2 + Experiment2$NBS_3 + Experiment2$NBS_4 + Experiment2$NBS_5 + Experiment2$NBS_6)/6),
mistrust = ((Experiment2$Mistrust_expertise_1 + Experiment2$Mistrust_expertise_2 + Experiment2$Mistrust_expertise_3)/3),
certainty = ((Experiment2$Certainty_sci_know_1 + Experiment2$Certainty_sci_know_2 + Experiment2$Certainty_sci_know_3 + Experiment2$Certainty_sci_know_4 + Experiment2$Certainty_sci_know_5 + Experiment2$Certainty_sci_know_6)/6),
development = ((Experiment2$Development_sci_know_1 + Experiment2$Development_sci_know_2 + Experiment2$Development_sci_know_3 + Experiment2$Development_sci_know_4 + Experiment2$Development_sci_know_5 + Experiment2$Development_sci_know_6)/6))
Experiment2 %>%
select(confusion:development)
## confusion backlash mistrust certainty development
## 1 1.833333 1.500000 2.000000 3.666667 4.333333
## 2 2.666667 3.000000 1.666667 4.666667 4.500000
## 3 1.666667 1.833333 2.333333 4.500000 5.000000
## 4 3.333333 3.666667 2.666667 3.666667 4.166667
## 5 4.000000 2.333333 1.666667 3.666667 4.500000
## 6 3.166667 2.833333 1.333333 3.833333 5.000000
## 7 3.500000 3.500000 3.000000 4.833333 4.666667
## 8 2.500000 2.833333 1.333333 3.333333 5.000000
## 9 3.000000 2.666667 2.666667 3.666667 4.500000
## 10 3.000000 2.666667 2.333333 3.166667 4.833333
## 11 3.000000 3.333333 3.000000 3.000000 2.500000
## 12 3.000000 3.166667 2.666667 3.666667 3.666667
## 13 2.666667 2.166667 2.000000 3.500000 4.500000
## 14 2.500000 2.000000 1.333333 4.166667 5.000000
## 15 3.666667 2.666667 2.666667 5.000000 5.000000
## 16 1.833333 1.666667 1.333333 4.333333 5.000000
## 17 3.666667 2.833333 1.333333 4.333333 5.000000
## 18 3.666667 2.666667 2.000000 5.000000 3.833333
## 19 3.333333 3.500000 2.000000 4.500000 4.666667
## 20 3.333333 2.500000 1.000000 4.333333 5.000000
## 21 3.833333 3.000000 1.666667 3.666667 4.500000
## 22 3.166667 1.666667 2.333333 4.833333 4.833333
## 23 3.000000 2.666667 2.000000 4.166667 4.333333
## 24 2.333333 2.166667 2.000000 4.500000 4.666667
## 25 3.166667 3.666667 1.333333 3.833333 5.000000
## 26 4.000000 4.500000 3.333333 4.666667 5.000000
## 27 2.333333 1.500000 2.000000 3.833333 5.000000
## 28 2.166667 2.500000 2.333333 4.000000 5.000000
## 29 4.000000 3.500000 2.666667 2.833333 4.333333
## 30 2.666667 2.166667 2.000000 4.833333 4.833333
## 31 2.166667 1.666667 1.666667 4.333333 4.833333
## 32 4.333333 3.666667 2.000000 3.666667 4.500000
## 33 2.666667 1.666667 1.333333 4.333333 5.000000
## 34 2.166667 2.666667 2.333333 5.000000 4.833333
## 35 3.166667 2.500000 1.666667 4.500000 4.333333
## 36 2.666667 2.666667 2.333333 3.500000 4.500000
## 37 3.333333 3.333333 3.000000 3.000000 3.500000
## 38 4.000000 2.666667 1.000000 3.666667 4.833333
## 39 2.333333 2.833333 1.000000 4.333333 4.833333
## 40 3.000000 3.500000 2.000000 4.333333 4.166667
## 41 3.333333 3.333333 2.000000 3.666667 4.166667
## 42 4.000000 4.000000 3.333333 4.666667 5.000000
## 43 2.666667 2.833333 2.666667 3.333333 3.666667
## 44 1.166667 1.333333 1.000000 4.500000 5.000000
## 45 3.166667 3.166667 2.333333 5.000000 5.000000
## 46 2.833333 3.000000 2.000000 3.333333 4.333333
## 47 1.500000 2.000000 1.000000 4.500000 4.833333
## 48 4.833333 2.500000 2.666667 4.333333 5.000000
## 49 3.333333 1.500000 1.000000 3.166667 4.333333
## 50 3.166667 3.166667 3.000000 3.833333 3.833333
## 51 3.666667 2.500000 2.000000 3.500000 5.000000
## 52 4.500000 3.333333 1.333333 3.666667 4.666667
## 53 3.000000 3.333333 3.000000 3.000000 4.166667
## 54 2.500000 2.333333 1.333333 4.666667 4.500000
## 55 1.833333 1.833333 1.333333 3.500000 4.166667
## 56 3.666667 3.333333 2.333333 3.833333 4.333333
## 57 2.333333 3.000000 1.666667 4.666667 4.500000
## 58 3.666667 3.000000 3.000000 4.166667 4.833333
## 59 4.333333 2.833333 2.666667 4.166667 4.333333
## 60 2.000000 2.500000 2.000000 4.500000 4.500000
## 61 3.333333 4.500000 2.000000 4.666667 5.000000
## 62 3.833333 2.333333 2.333333 4.500000 5.000000
## 63 2.166667 2.166667 2.333333 4.166667 5.000000
## 64 2.666667 3.666667 1.000000 3.333333 5.000000
## 65 3.833333 2.666667 2.000000 3.333333 4.000000
## 66 2.000000 2.000000 1.666667 4.166667 5.000000
## 67 3.166667 2.333333 2.000000 4.166667 5.000000
## 68 2.833333 1.666667 2.666667 2.333333 3.500000
## 69 3.333333 2.000000 1.666667 3.833333 4.833333
## 70 2.000000 2.333333 1.333333 3.666667 4.500000
## 71 2.500000 2.833333 1.333333 3.166667 5.000000
## 72 2.833333 2.833333 2.333333 4.666667 4.833333
## 73 2.500000 2.000000 1.333333 4.166667 4.166667
## 74 2.833333 2.500000 1.666667 4.166667 4.833333
## 75 4.333333 2.500000 2.333333 4.833333 5.000000
## 76 3.000000 2.000000 1.000000 3.333333 5.000000
## 77 3.000000 2.666667 1.000000 3.500000 3.666667
## 78 3.833333 3.666667 4.000000 4.333333 4.666667
## 79 3.000000 2.666667 2.666667 3.333333 4.000000
## 80 2.000000 2.166667 1.333333 4.833333 5.000000
## 81 3.333333 2.833333 1.333333 4.500000 4.500000
## 82 2.666667 1.833333 1.333333 4.166667 4.833333
## 83 2.000000 2.000000 1.000000 5.000000 5.000000
## 84 2.500000 3.333333 2.333333 3.833333 4.000000
## 85 4.500000 3.166667 1.666667 4.500000 4.833333
## 86 2.833333 2.666667 1.000000 4.333333 4.500000
## 87 2.000000 3.000000 2.333333 5.000000 4.333333
## 88 1.833333 1.166667 1.000000 4.166667 4.833333
## 89 4.000000 3.500000 2.000000 4.666667 4.833333
## 90 1.000000 1.500000 1.666667 4.666667 5.000000
## 91 2.333333 2.666667 1.000000 3.166667 4.666667
## 92 4.000000 3.166667 2.666667 4.000000 4.833333
## 93 3.333333 2.500000 2.666667 4.166667 5.000000
## 94 3.333333 1.333333 1.000000 3.500000 5.000000
## 95 3.833333 3.333333 2.000000 4.166667 4.000000
## 96 2.666667 2.666667 2.333333 3.500000 4.833333
## 97 3.500000 3.166667 3.000000 3.166667 3.166667
## 98 2.000000 2.333333 2.000000 4.166667 4.000000
## 99 3.500000 2.500000 2.333333 3.833333 4.166667
## 100 2.500000 2.833333 2.000000 4.333333 4.333333
## 101 3.166667 3.000000 3.000000 3.000000 3.166667
## 102 3.333333 2.833333 2.666667 4.166667 4.333333
## 103 3.000000 2.833333 2.666667 4.166667 4.333333
## 104 2.166667 2.166667 1.000000 3.500000 5.000000
## 105 3.666667 3.166667 2.000000 4.166667 5.000000
## 106 1.000000 1.500000 2.000000 2.833333 5.000000
## 107 2.166667 3.500000 2.666667 4.666667 5.000000
## 108 2.833333 2.000000 1.000000 4.000000 4.500000
## 109 2.500000 2.500000 2.333333 3.333333 3.666667
## 110 2.166667 2.500000 2.333333 4.000000 5.000000
## 111 2.833333 2.500000 1.666667 3.500000 4.666667
## 112 2.666667 1.666667 2.000000 3.833333 4.666667
## 113 1.500000 2.166667 1.000000 4.000000 4.500000
## 114 3.500000 2.333333 2.333333 3.666667 4.666667
## 115 2.000000 1.833333 1.000000 5.000000 5.000000
## 116 2.000000 1.833333 2.000000 4.000000 5.000000
## 117 3.500000 3.166667 3.333333 2.333333 3.833333
## 118 2.666667 2.833333 2.333333 4.000000 4.333333
## 119 4.000000 3.500000 2.333333 5.000000 5.000000
## 120 4.000000 4.166667 3.000000 5.000000 5.000000
## 121 3.000000 2.166667 1.666667 4.166667 4.000000
## 122 1.666667 2.500000 1.000000 3.666667 5.000000
## 123 2.833333 2.666667 2.000000 3.833333 4.333333
## 124 2.833333 1.666667 1.000000 4.666667 5.000000
## 125 3.166667 2.833333 2.333333 2.666667 4.833333
## 126 3.166667 2.333333 2.333333 3.500000 4.000000
## 127 4.500000 3.833333 2.333333 4.500000 4.666667
## 128 3.333333 3.166667 2.000000 3.833333 4.333333
## 129 2.000000 2.500000 1.333333 3.500000 5.000000
## 130 2.333333 2.333333 2.333333 4.500000 4.833333
## 131 2.333333 1.833333 1.000000 4.333333 4.000000
## 132 3.833333 2.666667 2.333333 3.666667 4.500000
## 133 3.166667 2.833333 2.666667 3.333333 4.333333
## 134 2.500000 2.666667 2.000000 3.166667 4.500000
## 135 2.833333 2.000000 2.000000 4.666667 5.000000
## 136 2.833333 2.666667 2.000000 3.000000 5.000000
## 137 2.833333 3.166667 2.333333 4.833333 5.000000
## 138 4.000000 1.833333 1.000000 3.500000 4.666667
## 139 3.333333 2.666667 2.000000 3.666667 4.500000
## 140 2.166667 3.000000 1.666667 3.000000 4.833333
## 141 3.333333 2.833333 1.333333 4.166667 4.166667
## 142 3.666667 3.000000 2.666667 4.833333 5.000000
## 143 3.166667 2.500000 2.333333 4.166667 4.666667
## 144 3.333333 3.833333 2.666667 4.000000 4.333333
## 145 3.500000 2.000000 1.000000 4.500000 4.500000
## 146 2.666667 2.166667 1.000000 4.833333 4.833333
## 147 1.166667 1.500000 1.000000 2.833333 5.000000
## 148 2.500000 2.666667 2.000000 4.333333 5.000000
## 149 2.000000 1.833333 1.333333 4.833333 4.500000
## 150 1.833333 2.500000 2.000000 4.333333 4.666667
## 151 3.500000 2.833333 2.333333 3.833333 4.000000
## 152 2.666667 2.666667 2.666667 3.666667 4.000000
## 153 3.000000 2.000000 2.000000 3.833333 4.333333
## 154 2.500000 2.666667 1.000000 4.166667 5.000000
## 155 3.333333 3.166667 3.000000 4.000000 4.833333
## 156 2.333333 2.000000 1.333333 4.166667 4.833333
## 157 3.000000 2.500000 2.000000 4.666667 5.000000
## 158 2.666667 2.500000 2.000000 3.666667 4.000000
## 159 3.333333 3.833333 2.333333 4.500000 4.833333
## 160 2.333333 2.666667 1.666667 4.333333 5.000000
## 161 1.000000 2.000000 2.333333 3.500000 5.000000
## 162 3.333333 3.500000 1.666667 4.333333 4.666667
## 163 3.666667 3.000000 1.666667 2.666667 4.166667
## 164 3.833333 3.333333 2.000000 4.833333 4.333333
## 165 3.333333 3.166667 2.000000 4.000000 5.000000
## 166 1.000000 2.166667 1.333333 4.833333 5.000000
## 167 4.666667 3.000000 1.333333 4.666667 5.000000
## 168 1.666667 2.000000 1.000000 3.333333 4.666667
## 169 3.166667 2.500000 1.666667 3.333333 4.333333
## 170 3.833333 3.333333 2.000000 3.833333 4.166667
## 171 3.166667 3.000000 3.000000 3.166667 4.000000
## 172 1.666667 2.500000 1.333333 4.500000 5.000000
## 173 2.000000 4.000000 2.000000 3.833333 4.000000
## 174 3.833333 4.000000 1.333333 4.333333 5.000000
## 175 3.000000 3.000000 2.333333 3.500000 3.833333
## 176 4.000000 3.500000 2.333333 3.333333 4.666667
## 177 3.666667 3.500000 1.666667 4.833333 4.666667
## 178 2.000000 2.333333 1.666667 3.500000 3.666667
## 179 2.666667 2.500000 3.000000 3.333333 4.166667
## 180 3.333333 2.333333 2.333333 3.833333 4.500000
## 181 2.833333 3.166667 2.333333 4.666667 5.000000
## 182 2.833333 2.333333 2.000000 3.500000 4.000000
## 183 2.333333 2.500000 1.333333 4.000000 4.500000
## 184 4.000000 2.500000 1.000000 4.833333 5.000000
## 185 2.000000 2.500000 1.333333 4.500000 4.666667
## 186 3.833333 3.500000 2.333333 3.500000 4.000000
## 187 3.000000 3.166667 2.000000 3.833333 5.000000
## 188 2.833333 3.000000 3.333333 2.833333 3.166667
## 189 3.000000 3.166667 1.666667 4.166667 4.833333
## 190 2.333333 1.833333 1.333333 4.833333 5.000000
## 191 2.500000 2.833333 2.666667 3.666667 4.833333
## 192 2.833333 2.333333 2.000000 4.500000 5.000000
## 193 3.000000 2.833333 2.333333 3.666667 4.500000
## 194 2.333333 2.166667 1.333333 3.000000 4.166667
## 195 3.000000 3.000000 1.666667 2.833333 5.000000
## 196 3.166667 2.166667 1.666667 4.000000 4.333333
## 197 2.666667 2.500000 2.000000 3.500000 4.000000
## 198 2.666667 2.166667 2.000000 3.500000 4.166667
## 199 3.000000 2.833333 3.000000 3.333333 4.333333
## 200 2.833333 2.833333 2.666667 3.500000 4.333333
## 201 2.666667 2.833333 1.000000 4.000000 4.500000
## 202 2.000000 3.666667 3.333333 4.500000 5.000000
## 203 2.833333 3.000000 1.333333 4.666667 3.666667
## 204 3.166667 2.666667 2.333333 2.666667 4.000000
## 205 2.500000 1.833333 1.333333 4.333333 4.166667
## 206 2.000000 2.500000 2.000000 4.166667 4.833333
## 207 4.000000 2.666667 2.333333 3.833333 4.833333
## 208 3.833333 3.500000 2.333333 3.000000 4.666667
## 209 4.833333 3.833333 1.333333 4.500000 5.000000
## 210 3.666667 3.166667 2.666667 2.833333 3.000000
## 211 3.166667 2.833333 2.666667 3.166667 3.500000
## 212 4.666667 3.500000 2.666667 2.166667 4.166667
## 213 1.500000 2.500000 1.000000 4.833333 5.000000
## 214 3.666667 2.666667 2.000000 4.166667 3.166667
## 215 3.500000 3.000000 3.000000 4.000000 4.000000
## 216 2.666667 2.833333 3.000000 3.166667 3.500000
## 217 3.166667 3.000000 2.333333 3.500000 4.166667
## 218 3.000000 2.000000 2.000000 4.000000 4.000000
## 219 2.666667 2.666667 2.000000 3.666667 4.000000
## 220 3.333333 2.166667 2.333333 4.833333 5.000000
## 221 4.333333 2.000000 2.333333 4.500000 4.666667
## 222 3.500000 2.500000 2.333333 2.666667 3.166667
## 223 2.333333 1.833333 1.333333 3.666667 4.833333
## 224 2.666667 3.500000 1.000000 4.333333 4.333333
## 225 1.833333 2.333333 1.000000 5.000000 5.000000
## 226 1.333333 1.833333 1.000000 3.500000 5.000000
## 227 2.833333 3.833333 2.666667 4.500000 5.000000
## 228 2.666667 2.500000 1.333333 3.666667 4.166667
## 229 1.666667 2.333333 1.666667 3.666667 3.833333
## 230 2.833333 4.000000 3.333333 3.500000 4.666667
## 231 3.000000 2.000000 2.000000 4.166667 5.000000
## 232 3.500000 3.000000 2.000000 4.000000 4.833333
## 233 3.666667 3.000000 2.000000 3.833333 5.000000
## 234 2.166667 3.666667 2.333333 4.666667 5.000000
## 235 2.833333 2.666667 2.666667 3.666667 5.000000
## 236 2.166667 2.666667 2.333333 3.166667 4.166667
## 237 2.500000 1.833333 1.666667 4.166667 5.000000
## 238 2.500000 2.500000 1.333333 4.500000 4.833333
## 239 3.000000 2.666667 2.000000 5.000000 5.000000
## 240 2.333333 2.000000 2.000000 5.000000 5.000000
## 241 1.333333 2.500000 1.000000 4.333333 5.000000
## 242 2.500000 3.500000 2.666667 4.666667 4.833333
## 243 3.166667 2.500000 1.666667 5.000000 5.000000
## 244 3.666667 3.333333 1.333333 3.500000 4.500000
## 245 2.500000 2.833333 2.000000 3.500000 4.833333
## 246 2.666667 3.166667 2.000000 3.500000 4.000000
## 247 2.000000 2.666667 2.000000 4.666667 4.333333
## 248 2.000000 2.500000 2.000000 4.000000 4.333333
## 249 2.666667 2.500000 1.333333 4.666667 5.000000
## 250 3.333333 2.500000 1.666667 4.666667 4.833333
## 251 4.000000 3.000000 2.333333 3.000000 5.000000
## 252 2.833333 3.000000 2.000000 4.166667 4.500000
## 253 3.333333 2.833333 1.000000 4.166667 4.833333
## 254 2.000000 2.166667 2.000000 4.666667 4.166667
## 255 2.666667 2.666667 1.000000 3.500000 5.000000
## 256 2.166667 3.500000 2.000000 4.833333 5.000000
## 257 2.500000 2.333333 2.000000 4.833333 4.166667
## 258 1.833333 2.333333 2.000000 4.500000 4.666667
## 259 3.166667 2.500000 1.666667 4.166667 4.000000
## 260 2.833333 3.166667 2.333333 5.000000 5.000000
## 261 3.166667 2.666667 2.000000 3.500000 4.333333
## 262 3.500000 2.166667 2.666667 2.166667 3.500000
## 263 3.333333 1.666667 2.333333 4.166667 4.666667
## 264 3.166667 2.333333 1.666667 4.333333 4.833333
## 265 3.500000 3.000000 3.000000 3.333333 4.333333
## 266 1.666667 1.333333 1.000000 5.000000 5.000000
## 267 2.500000 2.166667 2.000000 3.500000 4.166667
## 268 2.166667 3.000000 1.333333 4.666667 5.000000
## 269 1.500000 2.166667 1.333333 4.666667 5.000000
## 270 1.833333 2.166667 2.000000 4.333333 3.833333
## 271 2.166667 3.500000 2.666667 4.666667 4.833333
## 272 3.000000 2.166667 2.000000 3.166667 4.000000
## 273 2.666667 2.500000 1.000000 3.500000 4.166667
## 274 3.666667 3.833333 2.666667 4.833333 4.833333
## 275 1.833333 2.333333 1.000000 4.166667 5.000000
## 276 3.000000 2.333333 2.000000 4.000000 4.000000
## 277 3.166667 2.833333 2.000000 3.500000 4.333333
## 278 2.833333 3.166667 1.666667 3.500000 4.666667
## 279 3.666667 1.666667 1.333333 4.333333 5.000000
## 280 3.166667 2.666667 2.666667 3.666667 4.000000
## 281 3.833333 2.333333 1.000000 4.166667 5.000000
## 282 3.000000 3.166667 1.666667 5.000000 4.833333
## 283 3.666667 4.000000 2.333333 3.166667 4.166667
## 284 1.833333 2.333333 2.000000 4.000000 4.666667
## 285 2.000000 3.000000 2.666667 3.666667 4.166667
## 286 3.833333 2.500000 1.666667 3.833333 4.500000
## 287 3.333333 3.500000 3.000000 2.666667 4.000000
## 288 3.000000 3.000000 1.000000 4.500000 5.000000
## 289 3.833333 4.000000 2.333333 4.666667 5.000000
## 290 1.333333 1.666667 1.333333 5.000000 5.000000
## 291 3.333333 2.333333 2.000000 3.500000 4.166667
## 292 2.500000 2.500000 2.333333 4.500000 4.666667
## 293 3.000000 2.500000 2.333333 3.333333 4.666667
## 294 2.000000 2.500000 1.666667 4.000000 4.333333
## 295 2.333333 2.166667 2.666667 2.166667 3.833333
## 296 2.000000 2.166667 1.666667 4.666667 3.666667
## 297 2.833333 2.833333 1.333333 4.500000 4.166667
## 298 4.333333 3.666667 3.000000 3.833333 4.333333
## 299 1.666667 2.833333 1.666667 4.666667 4.166667
## 300 2.000000 2.666667 3.000000 4.000000 3.666667
## 301 2.666667 1.833333 1.000000 2.833333 4.166667
## 302 3.333333 3.500000 2.000000 4.166667 4.000000
## 303 1.333333 2.166667 3.333333 2.500000 5.000000
## 304 3.500000 2.666667 2.000000 3.833333 4.833333
## 305 3.166667 3.500000 2.333333 4.666667 5.000000
## 306 3.333333 3.166667 2.000000 4.500000 4.500000
## 307 3.500000 2.000000 3.000000 3.333333 4.666667
## 308 2.500000 2.666667 1.333333 3.833333 5.000000
## 309 3.166667 2.333333 2.000000 3.000000 5.000000
## 310 1.666667 1.666667 1.666667 4.333333 5.000000
## 311 2.333333 2.333333 1.333333 4.000000 4.166667
## 312 2.166667 3.666667 2.000000 3.666667 5.000000
## 313 3.333333 2.166667 1.666667 3.333333 4.000000
## 314 3.000000 1.500000 1.000000 4.833333 5.000000
## 315 4.166667 4.666667 5.000000 1.000000 5.000000
## 316 1.833333 1.500000 2.666667 3.333333 5.000000
## 317 4.333333 3.833333 1.000000 4.666667 4.000000
## 318 2.000000 2.166667 2.000000 3.833333 4.666667
## 319 4.000000 2.666667 2.333333 3.166667 4.666667
## 320 2.333333 2.500000 2.000000 4.833333 5.000000
## 321 2.666667 2.333333 1.333333 3.500000 4.166667
## 322 2.500000 2.166667 2.666667 3.666667 3.666667
## 323 3.500000 2.166667 1.333333 4.000000 5.000000
## 324 2.166667 1.833333 1.333333 4.166667 5.000000
## 325 2.500000 2.000000 2.333333 3.833333 4.166667
## 326 2.333333 3.000000 1.666667 3.666667 3.333333
## 327 2.000000 2.000000 2.333333 4.666667 4.833333
## 328 2.000000 1.666667 1.000000 4.166667 5.000000
## 329 4.000000 2.666667 2.000000 4.333333 5.000000
## 330 2.833333 1.666667 1.666667 3.833333 5.000000
## 331 3.000000 2.666667 1.000000 4.000000 4.166667
## 332 4.000000 2.500000 2.000000 4.333333 5.000000
## 333 3.666667 2.000000 2.000000 3.666667 4.333333
## 334 2.500000 3.000000 2.000000 3.500000 4.000000
## 335 3.333333 3.666667 2.333333 3.833333 4.333333
## 336 2.666667 2.833333 3.333333 3.500000 4.500000
## 337 3.666667 3.333333 3.666667 3.166667 4.833333
## 338 3.333333 3.166667 2.000000 3.666667 4.166667
## 339 2.333333 2.500000 1.333333 4.333333 5.000000
## 340 3.000000 3.333333 2.333333 4.833333 4.333333
## 341 4.000000 2.833333 1.666667 4.166667 5.000000
## 342 2.000000 1.666667 1.333333 3.166667 4.833333
## 343 2.000000 2.000000 2.000000 3.833333 4.833333
## 344 4.000000 2.666667 2.333333 4.333333 4.666667
## 345 3.333333 1.666667 1.000000 4.500000 5.000000
## 346 2.500000 2.833333 2.000000 4.166667 4.166667
## 347 2.666667 2.333333 1.666667 4.333333 4.333333
## 348 1.500000 1.166667 1.000000 4.666667 5.000000
## 349 1.833333 2.833333 3.000000 3.666667 3.833333
## 350 3.500000 2.833333 2.000000 4.333333 4.666667
## 351 2.833333 3.000000 3.000000 3.000000 3.000000
## 352 2.166667 1.666667 1.333333 3.666667 3.833333
## 353 2.500000 2.666667 1.333333 4.166667 5.000000
## 354 3.166667 1.666667 1.000000 4.000000 4.833333
## 355 2.833333 2.833333 2.666667 3.500000 3.833333
## 356 2.500000 2.666667 2.000000 3.666667 4.166667
## 357 2.666667 2.666667 1.000000 3.833333 5.000000
## 358 2.166667 3.000000 4.000000 2.000000 4.500000
## 359 2.500000 2.166667 2.666667 3.666667 3.666667
## 360 2.166667 2.500000 2.000000 4.333333 5.000000
## 361 2.833333 2.333333 2.333333 4.666667 4.833333
## 362 2.000000 1.000000 1.000000 4.833333 5.000000
## 363 1.333333 1.500000 1.333333 4.000000 4.833333
## 364 1.833333 2.833333 1.000000 3.666667 4.333333
## 365 2.666667 3.333333 2.666667 4.666667 4.666667
## 366 2.500000 2.166667 2.000000 3.833333 4.500000
## 367 3.000000 3.666667 2.333333 4.333333 5.000000
## 368 3.500000 3.000000 1.666667 4.333333 5.000000
## 369 2.666667 2.500000 2.000000 4.333333 5.000000
## 370 2.666667 3.000000 2.333333 3.166667 4.500000
## 371 4.333333 2.500000 1.333333 3.833333 4.500000
## 372 4.333333 4.000000 1.666667 3.000000 4.500000
## 373 3.500000 2.333333 1.666667 3.500000 4.000000
## 374 2.333333 2.166667 2.333333 2.000000 4.333333
## 375 4.166667 2.666667 2.000000 4.833333 5.000000
## 376 4.000000 3.000000 2.000000 3.666667 4.666667
## 377 3.166667 3.666667 2.333333 4.500000 5.000000
## 378 2.166667 2.666667 2.333333 4.166667 5.000000
## 379 1.833333 2.666667 2.666667 3.666667 4.000000
## 380 3.166667 2.666667 2.000000 4.333333 4.333333
## 381 2.333333 3.500000 2.000000 4.333333 4.666667
## 382 4.333333 3.333333 3.000000 2.833333 4.000000
## 383 2.333333 1.333333 1.000000 4.500000 5.000000
## 384 2.666667 2.666667 1.666667 4.166667 4.833333
## 385 1.833333 2.333333 1.666667 3.500000 4.166667
## 386 3.500000 2.833333 2.000000 3.833333 4.500000
## 387 2.666667 3.333333 2.333333 4.000000 4.333333
## 388 2.500000 3.833333 2.333333 4.166667 4.833333
## 389 1.500000 2.500000 1.666667 4.333333 4.833333
## 390 3.666667 2.833333 2.333333 2.000000 3.666667
## 391 3.166667 2.833333 1.666667 3.833333 5.000000
## 392 4.000000 3.333333 2.000000 4.666667 4.666667
## 393 3.166667 5.000000 4.000000 3.666667 5.000000
## 394 3.500000 3.166667 1.666667 4.666667 4.333333
## 395 3.333333 3.500000 2.000000 4.833333 4.666667
## 396 3.166667 2.333333 1.666667 3.666667 4.333333
## 397 2.833333 2.333333 1.333333 4.333333 4.666667
## 398 2.500000 3.500000 1.333333 2.500000 4.833333
## 399 3.833333 3.333333 1.666667 3.833333 3.666667
## 400 3.333333 2.333333 2.000000 3.666667 4.333333
The package needed here is ggplot2.
For each one of these plots: We are using the ggplot() function to set the x- and y-axes, and to fill the violinplot with colors according to conflict. Geom_violin() is used to create violinplots. Geom_beeswarm() is used to add dotpoints to the violinplots and to remove the legend of the dotpoints done by setting legend.position to ‘none’.
To indicate the condition mean and 95% confidence intervals, geom_crossbar() is used. Since we have already set the mapping and data in the ggplot() function, mapping and data are set to NULL. Then, setting the vector fun.y as “mean_ci” as we want mean and confidence intervals. The fill and alpha are adjusted to white and 0.7 respectively to match the aesthetics of the crossbars that authors have used. Additionally, because the variables on the y-axes are continuous, we are using scale_y_continuous().
Then, using the facet_wrap() function, we are dividing the plots by format and changing facet titles to be at the bottom rather than top. Using ggtitle(), we are adding a title for each of these plots (“Contradiction”, “Advancement”, “Confusion”). Also, we fixed the aesthetics of the violin plots to make it look as similar to the authors’ using the function theme(). Firstly, the function theme_bw() removes the default grey background. Then, several arguments within theme are used: 1. The argument plot.title = element_text(hjust= 0.5) centres the titles 2. The argument axis.line = element_line(colour = “black”) makes the axis lines black. 3. The argument panel.grid.major.x = element_blank() and panel.grid.minor.x = element_blank() removes the vertical gridlines.
# Nutritional confusion plot
confusionplot <- ggplot(Experiment2,
aes(x= Conflict,
y= confusion,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Nutritional Confusion") +
scale_y_continuous(name = "Nutritional Confusion",
expand = c(0, 0)) +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(confusionplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
# Nutritional backlash plot
backlashplot <- ggplot(Experiment2,
aes(x= Conflict,
y= backlash,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Nutritional Backlash") +
scale_y_continuous(name = "Nutritional Backlash") +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(backlashplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
# Mistrust of expertise plot
mistrustplot <- ggplot(Experiment2,
aes(x= Conflict,
y= mistrust,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Mistrust of Expertise") +
scale_y_continuous(name = "Mistrust of expertise") +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(mistrustplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
# Confidence in scientific community plot
confidenceplot <- ggplot(Experiment2,
aes(x= Conflict,
y= GSS,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Confidence in Scientific Community") +
scale_y_continuous(name = "Confidence in Scientific Community") +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(confidenceplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
# Certainty of knowledge plot
certaintyplot <- ggplot(Experiment2,
aes(x= Conflict,
y= certainty,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Certainty of Knowledge") +
scale_y_continuous(name = "Certainty of Knowledge") +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(certaintyplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
# Development of knowledge plot
developmentplot <- ggplot(Experiment2,
aes(x= Conflict,
y= development,
fill = Conflict)) +
geom_violin() +
geom_beeswarm(cex = 0.2) +
geom_crossbar(mapping = NULL,
data = NULL,
stat= "summary",
fun.y = "mean_ci",
fill = "white",
alpha = 0.7) +
facet_wrap(vars(Format), strip.position = "bottom") +
ggtitle(label= "Development of Knowledge") +
scale_y_continuous(name = "Development of Knowledge") +
scale_fill_manual(values = c("slategray2", "lightpink1")) +
theme(axis.line = element_line(colour = "black")) +
theme_bw() +
theme(plot.title = element_text(hjust= 0.5)) +
theme(legend.position = "none") +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())
print(developmentplot)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
We are using the package patchwork to combine the different violin plots into one graph. When combined, the plots appeared cramped together. A quick fix to this is to change the width and height of the graphs in the code chunk. {r, fig.width=10,fig.height=11}
# Combining descriptive plots
combinedplots <- (confusionplot | backlashplot)/(mistrustplot | confidenceplot)/(certaintyplot | developmentplot)
print(combinedplots)
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`