I have a dataset df. I would like to make two groups, containing a= Special and b=Up+ Down+ Left. Then I would like to have 2x determination coefficient and 2 regression lines for each subgroup in one plot. Problem is how to call these created subsets and not overplot my R2. With this code, I make a line for each single group.
library(tidyverse) set.seed(2013) Place <- sample(c("Up", "Down", "Left", "Special"), 100, replace = TRUE) Value <- sample(200:1500, 100, replace = TRUE) Conc <- sample(1:25, 100, replace = TRUE) df <- tibble(Place, Value, Conc) #make subgroup only Special a <- df |> filter(Place == "Special") #make subgroup Up+Down+Left U <-"Up" D <-"Down" L <-"Left" Subgroup <- c(U,D,L) b <- df |> filter(Place %in% Subgroup) #Scatter and Regression for all Place seperated df |> ggplot(aes(Value, Conc))+ geom_point(aes(col = Place))+ stat_poly_line(aes(col = Place), se = FALSE)+ stat_poly_eq() 