0

enter image description hereI am working on a project in which I have to put labels on my chart for the boundaries(encircles) around some scatter points.[![enter image description here][2]][2]

As it is shown in the picture, I want to put GrainSize labels on the three encircled boundaries inside triangle. I am using geom_encircle() command from ggalt package with ggplot2.

For example: The plot above has 3 categories, Setosa, Versicolor and Verginica I want these labels to be placed on classification boundaries as well, Like the eclips of setosa should be labeled as setosa and similarly 2 other categories. I found ggforce package usefule but that is limited for eclips or circle shapes only, is there any way that I can put label on these three encircles(Setosa, Versicolor and Verginica)

Phil
  • 7,287
  • 3
  • 36
  • 66
Rahul Kumar
  • 39
  • 1
  • 11
  • OP, can you provide some sample data and the code for the plot so that it can be replicated and we can help you? Also, it's not clear what you're looking to do... add the text "coarse", "Fine" and "Medium" to the plot area inside the ternary plot? – chemdork123 Sep 14 '21 at 04:09
  • Sorry, the question might not be clear then, now it is clear I guess that i want to put labels to the encircled lines around classified iris flowers(Setosa, Versicolor and Verginica) – Rahul Kumar Sep 14 '21 at 05:52

1 Answers1

1

You could try by creating a separate label dataframe and position the grouping labels as you wish; have gone for a simple solution here.

library(ggplot2)
library(ggalt)
library(dplyr)

labs <- 
  iris %>% 
  group_by(Species) %>% 
  filter(Sepal.Length == max(Sepal.Length))
  

ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species))+
  geom_point()+
  geom_encircle(expand = 0.01)+
  geom_text(data = labs, 
            aes(Sepal.Width, Sepal.Length, label = Species),
            nudge_y = 0.15)+
  theme(legend.position = "none")

Created on 2021-09-14 by the reprex package (v2.0.0)

Peter
  • 11,500
  • 5
  • 21
  • 31
  • Many thanks, it worked but the labels are far from the encircle boundaries, consider that my data has distant values. – Rahul Kumar Sep 14 '21 at 15:57
  • Without seeing your data it is difficult to say; you can control the x and y locations using `nudge_x` and `nudge_y` in call to `geom_text`; you will have to experiment. You can also manage the placement of your labels by selecting alternative filter criteria, not `max` – Peter Sep 14 '21 at 16:00
  • Yes I tried by adding nudge_x( ) values and changing nudge_y( ) but that changes the size of the plot as well, never mind it suffice the purpose, many thanks for your prompt response and kindness. – Rahul Kumar Sep 14 '21 at 16:02
  • Hmm, seems odd; without seeing the full code and data, I'm struggling a bit to know what to suggest... – Peter Sep 14 '21 at 16:06