I am trying to create scatter plots of all the combinations for the columns: insulin
, sspg
, glucose
(mclust, diabetes dataset, in R) with class as the colo(u)r. By that I mean insulin with sspg, insulin with glucose and sspg with glucose.
And I would like to do that with tidyverse, purrr, mappings and pipe operations. I can't quite get it to work, since I'm relatively new to R and functional programming.
When I load the data I've got the columns: class, glucose, insulin and sspg. I also used pivot_longer
to get the columns: attr and value but I was not able to plot it and don't know how to create the combinations.
I assume that there will be an iwalk()
or map2()
function at the end and that I might have to use group_by()
and nest()
and maybe combn(., m=2)
for the combinations or something like that. But it will probably have some way simpler solution that I can not see myself.
My attempts have amounted to this:
library(mclust)
library(dplyr)
library(tibble)
data(diabetes)
diabTib <- tibble::as_tibble(diabetes)
plot <- diabTib %>%
pivot_longer(cols = !c(class), names_to = "attr", values_to = "value") %>%
group_by(attr) %>%
nest()
At the end there should be three plots on the screen when I execute plot or during the pipeline as a side effect(?).
Help would be appreciated.