Skip to main content
deleted 544 characters in body
Source Link
Allan Cameron
  • 178.4k
  • 7
  • 70
  • 118

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics ofspecify the originalgroup using a simple ggplotifelse call, in which case the mapping will be inherited to all other layers:get groups "a" and "b".

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() + aes(group = theme_bwifelse(Place == "Special", "group~a", "group~b"),  

enter image description here

If you want the equations to be black, you could instead aes(group = Place), colour = "black" inside stat_poly_eq. However, you will then need to construct direct labels for the equations otherwise it will not be clear to which line each equation belongs. This could be something like:

df |>    ggplot(aes(Value, Conc, colour = Place)) +  geom_point() +  stat_poly_line(se = FALSE) +  stat_poly_eq(aes(blah = ifelse(Place == "Special", "group~a", "group~b"), label = paste0(after_stat(blah), ": ", after_stat(rr.label))), colour = "black") + theme_bw() 

enter image description hereenter image description here

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics of the original ggplot call, in which case the mapping will be inherited to all other layers:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() +  theme_bw() 

enter image description here

If you want the equations to be black, you could instead aes(group = Place), colour = "black" inside stat_poly_eq. However, you will then need to construct direct labels for the equations otherwise it will not be clear to which line each equation belongs. This could be something like:

df |>    ggplot(aes(Value, Conc, colour = Place)) +  geom_point() +  stat_poly_line(se = FALSE) +  stat_poly_eq(aes(blah = Place, label = paste0(after_stat(blah), ": ", after_stat(rr.label))), colour = "black") + theme_bw() 

enter image description here

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can specify the group using a simple ifelse to get groups "a" and "b".

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq(aes(group = ifelse(Place == "Special", "group~a", "group~b"),  blah = ifelse(Place == "Special", "group~a", "group~b"), label = paste0(after_stat(blah), ": ", after_stat(rr.label))), colour = "black") + theme_bw() 

enter image description here

added 523 characters in body
Source Link
Allan Cameron
  • 178.4k
  • 7
  • 70
  • 118

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics of the original ggplot call, in which case the mapping will be inherited to all other layers:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() + theme_bw() 

enter image description here

If you want the equations to be black, you could instead aes(group = Place), colour = "black" inside stat_poly_eq. However, you will then need to construct direct labels for the equations otherwise it will not be clear to which line each equation belongs. This could be something like:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq(aes(blah = Place, label = paste0(after_stat(blah), ": ", after_stat(rr.label))), colour = "black") + theme_bw() 

enter image description here

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics of the original ggplot call, in which case the mapping will be inherited to all other layers:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() + theme_bw() 

enter image description here

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics of the original ggplot call, in which case the mapping will be inherited to all other layers:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() + theme_bw() 

enter image description here

If you want the equations to be black, you could instead aes(group = Place), colour = "black" inside stat_poly_eq. However, you will then need to construct direct labels for the equations otherwise it will not be clear to which line each equation belongs. This could be something like:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq(aes(blah = Place, label = paste0(after_stat(blah), ": ", after_stat(rr.label))), colour = "black") + theme_bw() 

enter image description here

Source Link
Allan Cameron
  • 178.4k
  • 7
  • 70
  • 118

You haven't specified a grouping variable for the stat_poly_eq layer. In the geom_point layer and stat_poly_line layer, you have mapped the "colour" aesthetic to the Place column, but you haven't done this for stat_poly_eq, so a single R2 value is produced. You can either supply this directly as you did in the other layers, or you can pass colour = Place in the aesthetics of the original ggplot call, in which case the mapping will be inherited to all other layers:

df |> ggplot(aes(Value, Conc, colour = Place)) + geom_point() + stat_poly_line(se = FALSE) + stat_poly_eq() + theme_bw() 

enter image description here

Notice added Posted by Recognized Member/Admin in R Language Allan Cameron