I have the following data:
HDL=c(26.41779, 45.99568, 70.74717, NA, 22.35012, 60.46269, 48.03072, 23.87873 ,54.92130 ,64.95151, 57.94742, 44.75888 ,32.57670,
39.26278, 53.05259, 38.76336, 74.73936, 63.62279, 99.27376, 35.42466, 35.48192, 43.56407, 45.23391, 58.27397, 15.15950, 46.20695,
35.95102, 55.05239, 39.73222, 53.68377, 35.21194, 95.44346, 38.53242, 62.78161, 56.30534, 67.35458, 22.75741, 51.94800, 66.61517,
35.35236)
LDL=c(183.83648, 169.59815 ,106.58631 ,137.96398, 164.25937, 94.39745, 189.70669, 167.62298 ,176.85359, 127.54434, 115.63603, 140.43276,
165.68687, 150.71473, 131.29033, 150.66534, 137.26902, 156.01673, 118.18147, NA, 161.35154, 157.89021, 138.93356, 139.51652,
206.24948, 168.27322, 176.91744, 92.03747, 144.61200, 127.93379, 142.59781, 88.22650, 157.32140, 149.79619, 121.23857, 141.68063,
173.50586, 133.91838, 123.99608, 138.68897)
BMI=c(35, 33 ,25, 27 ,31, 21, 32, 34, 33, 29, 23, 27, 33, 26, 26, 32, 25, 30, 22, 36, 33, 30, 27, 29, 36, 35, 35, 20, 29, 27, 29, 20, 32, 30, 22, 29, 33, 27, 22, 28)
newdf=data.frame(HDL, LDL, BMI)
newdf$BMI_group[newdf$BMI<25]="lean"
newdf$BMI_group[newdf$BMI>=25 & newdf$BMI<30]="overweight"
newdf$BMI_group[newdf$BMI>=30]="obese"
The data is completely fictitious. When I use the following code, facet_grid or facet_wrap do not split the plot correctly regarding the grouping variable.
ggplot(data = plotdf, aes(x = plotdf$HDL, y = plotdf$LDL)) +
geom_point() +
facet_wrap(~BMI_group)
In detail, it is splitted but e.g. there are no lean patients which have LDL of over 150 within the df. But the plot shows me exactly this. Maybe I have a error in reasoning.
I have no solution or explanation for this behavior. Hope you can help me.
Edit: I added the data like suggested by @Roland