0

Right now I am working with my own dataset, which is very similar to the example at https://www.datanovia.com/en/lessons/anova-in-r/, specifically the Three-Way ANOVA section. The code is well laid out, but when I get to the section for visualization using boxplots, I run into an unexpected error.

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")

In their code, they assign y as pain score, but for me, I get an error when running it in R:

FUN (x[[i]],...) : object "pain_score" not found

As such, I can't get the plot they make or move farther into analysis.

  bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
  )
bxp

All of the packages I have are up to date and I'm not seeing any errors in my code. I've tried other variables in my data set and still have the same issue. When I change it to the mean, I just get the line, not the box plot. If anyone has some input, it would be much appreciated!!

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
reeto9
  • 11
  • 2
  • 1
    Can you `dput(head())` your `data` please? – Serkan Mar 20 '21 at 06:11
  • 1
    At least a `str()` of your data is needed. Better would be `dput()` head of your data as Serkan has suggested. I think there is a minor issue, that can be solved. – TarJae Mar 20 '21 at 06:48

1 Answers1

2

Its working perfectly alright, You also didn't mention the libraries in your code. Its hard to help if you don't provide all the complete information. In any case someone wants to reproduce this.

Please run the below, It should work at your end. The error you are getting suggests that you might have either mistakenly removed the column, or data is corrupt in your session.

Here is the complete working code:

library(tidyverse)
library(rstatix)
library(ggpubr)

data("headache", package = "datarium")

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")


bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
)
bxp
PKumar
  • 10,971
  • 6
  • 37
  • 52