I'm doing a study testing if turkey and alcohol affects the level of contentedness and levels of drowsiness of participants. It's a repeated measures design, so the participants get asked their level of contentedness and drowsiness on a 1-7 scale.
We then made the data set and I’ll copy how I did that below.
Drowsy1 <- c(4, 5, 1, 5, 2, 5, 1, 2, 1, 2, 3, 4, 2, 2, 5, 5, 3, 1, 1, 4, 1, 1, 1, 1, 3, 2, 3, 1, 6, 1, 5, 1, 3, 2, 1, 3)
Drowsy2 <- c(3, 4, 2, 6, 3, 5, 2, 3, 3, 2, 3, 4, 3, 3, 6, 4, 6, 6, 4, 7, 4, 7, 3, 7, 6, 6, 1, 2, 1, 1, 6, 5, 7, 1, 7, 5)
Drowsy3 <- c(6, 2, 6, 7, 4, 7, 2, 6, 4, 6, 7, 6, 5, 5, 4, 3, 7, 6, 7, 5, 6, 5, 6, 7, 7, 6, 6, 7, 5, 7, 7, 6, 7, 5, 7, 6)
Content1 <- c(5, 4, 5, 5, 5, 6, 7, 5, 3, 5, 3, 3, 3, 4, 3, 3, 4, 7, 7, 6, 6, 5, 4, 1, 4, 2, 4, 5, 4, 3, 3, 76, 4, 4, 6)
Content1 <- c(5, 4, 5, 5, 5, 6, 7, 5, 3, 5, 3, 3, 3, 4, 3, 3, 4, 7, 7, 6, 6, 5, 4, 1, 4, 2, 4, 5, 4, 3, 3, 7, 6, 4, 4, 6)
content2 <- c(5, 3, 6, 4, 5, 4, 6, 5, 4, 6, 5, 2, 5, 4, 4, 4, 6, 7, 7, 7, 7, 7, 5, 7, 6, 3, 7, 7, 7, 5, 7, 7, 3, 7, 6, 7)
content3 <- c(4, 6, 3, 2, 5, 5, 7, 4, 7, 7, 5, 2, 5, 6, 5, 7, 5, 7, 7, 7, 7, 6, 7, 7, 7, 5, 7, 6, 3, 6, 7, 7, 6, 7, 7, 6)
turkeydata <- data.frame(Drowsy1, Drowsy2, Drowsy3, Content1, content2, content3)
id.num = c(1:nrow(turkeydata))
turkeydata <- cbind(id.num, turkeydata)
colnames(turkeydata) = c("id.num", "drowsy_noalc_noturk", "drowsy_alc_noturk", "drowsy_alc_turk", "content_noalc_noturk", "content_alc_noturk", "content_alc_turk")
print(turkeydata)
install.packages("lsr")
library(lsr)
turkeydata2 <- wideToLong(turkeydata, within = c("alcohol consumption"," turkey consumption")) View(turkeydata2)
Then, I tried to make a graph and it says there’s an unexpected symbol in the code.
ggbarplot[turkeydata2 (turkeydata2, "turkey consumption", "drowsy",
color = "alcohol consumption", palette = c("#0072B2", "#E69F00"),
add = "mean_ci", position = position_dodge(0.9)) +
scale_y_continuous(expand = c(0,0)) +
coord_cartesian(ylim = c(0,7))+
labs(y = "Likert Scale Ratings(1-7)")
Then I tried reformatting the data and renaming it to a format I thought r would like better. I also split up the data set so it would be just one data set looking at turkey and alcohol (the two IVs) and just looking at one DV at a time (in this case drowsiness). I’ll paste that below.
Drowsy1 <- c(4, 5, 1, 5, 2, 5, 1, 2, 1, 2, 3, 4, 2, 2, 5, 5, 3, 1, 1, 4, 1, 1, 1, 1, 3, 2, 3, 1, 6, 1, 5, 1, 3, 2, 1, 3)
Drowsy2 <- c(3, 4, 2, 6, 3, 5, 2, 3, 3, 2, 3, 4, 3, 3, 6, 4, 6, 6, 4, 7, 4, 7, 3, 7, 6, 6, 1, 2, 1, 1, 6, 5, 7, 1, 7, 5)
Drowsy3 <- c(6, 2, 6, 7, 4, 7, 2, 6, 4, 6, 7, 6, 5, 5, 4, 3, 7, 6, 7, 5, 6, 5, 6, 7, 7, 6, 6, 7, 5, 7, 7, 6, 7, 5, 7, 6)drowsyturkey <- data.frame(Drowsy1, Drowsy2, Drowsy3)
id.num = c(1:nrow(drowsyturkey))
drowsyturkey <- cbind(id.num, drowsyturkey)
View(drowsyturkey)
colnames(drowsyturkey) = c("id.num", "drowsy_alcno_turkno", "drowsy_alcyes_turkno", "drowsy_alcyes_turkyes")
drowsyturkey2 <- wideToLong(drowsyturkey, within = c("Alcohol Consumption", "Turkey Consuption"))
View(drowsyturkey2)
Then, I tried to make a graph one more time…. It did not work:
ggbarplot[drowsyturkey2(drowsyturkey2, "Turkey Consumption", "drowsy",
color = "Alcohol Consumption", palette = c("#0072B2", "#E69F00"),
add = "mean_ci", position = position_dodge(0.9))+
scale_y_continuous(expand = c(0,0)) +
coord_cartesian(ylim = c(0, 7)) +
labs(y = "Drowsiness Scale Rating (1-7)")
This is the error I get in result:
ggbarplot[drowsyturkey2(drowsyturkey2, "Turkey Consumption", "drowsy",
color = "Alcohol Consumption", palette = c("#0072B2", "#E69F00"),
- scale_y_continuous(expand = c(0,0)) +
- labs(y = "Drowsiness Scale Rating (1-7)")
add = "mean_ci", position = position_dodge(0.9))+
Error: unexpected symbol in:
" labs(y = "Drowsiness Scale Rating (1-7)")
add"
add = "mean_ci", position = position_dodge(0.9))+
Error: unexpected ',' in " add = "mean_ci","
If you can help me out that would be awesome, Thanks.