I have a two continuous variables, one of which I have categorized in two groups. I want a scatterplot of the original variables over a boxplot of the categorized variable:
library(ggplot2)
data(cancer, package="survival")
lung$age2 <- lung$age >= 75
## Boxplot
ggplot(lung, aes(x=age2, y=wt.loss)) +
geom_boxplot()
#> Warning: Removed 14 rows containing non-finite values (stat_boxplot).
## Scatterplot
ggplot(lung, aes(x=age, y=wt.loss)) +
geom_point()
#> Warning: Removed 14 rows containing missing values (geom_point).
Created on 2022-02-11 by the reprex package (v2.0.1)
I want the two graphs together, with the boxplot drawn at 50 and 70. Is that possible? ggplot2
preferred.