Many thanks mister FJCC.
So here is the reproducible example. The one which says: Object 'Sex' not found.
What am I doing wrong? Is there another way to code this in order to remove the extreme values?
Best regards,
M
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df<-data.frame(drating = c(0, -2, -2, 18.2125, 3.587, 0, -2, 0, 0, 0, -2, -2, 1.7155, 0.116, -2, -2, 0.058, 4.5, 0.808, 0.145), JntInc = c(3L, 3L, 3L, 19L, 19L, 19L, 19L, 8L, 18L, 18L, 18L, 18L, 21L, 21L, 21L, 21L, 6L, 6L, 19L, 19L), Sex = as.factor(c("Female", "Male", "Female", "Male", "Female", "Female", "Female", "Male", "Female", "Male", "Male", "Female", "Male", "Female", "Female", "Male", "Female", "Male", "Male", "Female")))
is_outlier<-function(x){return(x<quantile(x,0.25)-1.5*IQR(x)|x>quantile(x,0.75)+1.5*IQR(x))}
incomeplot<-df%>%select(drating,JntInc)%>%mutate(outlier=is_outlier(drating))%>%filter(drating>=0 & outlier==FALSE &JntInc<=31 & JntInc>0)%>%ggplot(aes(x=drating,y=JntInc,colour=Sex)+geom_point()+labs(title="Alcohol Consumption Based on Income", "Alcohol Units", "Annual Income"))
#> Error in aes(x = drating, y = JntInc, colour = Sex) + geom_point() + labs(title = "Alcohol Consumption Based on Income", : non-numeric argument to binary operator
Created on 2019-04-08 by the reprex package (v0.2.1)