0

I'm learning R and I have a dataset with Pad_Number as categorical variable of Pad_1, Pad_2 etc. I am trying to filter the data but I get this error

Error in dplyr::filter(Pad_Number, Comfort_Level > 0, Pain_Level > 2) : object 'Pad_Number' not found

With this input:

ggplot(data = Breast_Coil_Comfort, mapping = aes(x = Comfort_Level, y = Pain_Level)) +
  geom_point() + 
  geom_point(data = dplyr::filter(Pad_Number, Comfort_Level > 0, Pain_Level > 2), colour = "red", size = 2.2)
yfalls
  • 1
  • 3
  • 3
    `dplyr::filter`'s first argument needs to be a frame, but that's not what you're trying to do. Are you attempting to set a new `x=` or `y=` variable with the filtered data? Perhaps something like `geom_point(data = ~ dplyr::filter(., Comfort_Level > 0, Pain_Level > 2), colour = "red", size = 2.2)`? This assumes the x and y are the same variables, but you're highlighting specific points (and double-plotting them, btw). This would be easier to address if you provided sample data, please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info (then use `dput`). – r2evans Jul 30 '21 at 17:39

1 Answers1

0

I found the answer after some struggles:

geom_point(data = dplyr::filter(Pad_Number, Comfort_Level > 0, Pain_Level > 2), colour = "red", size = 2.2)

Pad_Number is a variable, and the correct input there should be the Dataset Name, not a variable. I changed it to Breast_Comfort (Dataset name) and it filtered properly.

yfalls
  • 1
  • 3