Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding extra text/labels to Euler diagram. #70

Open
JustGitting opened this issue Jun 26, 2020 · 3 comments
Open

Adding extra text/labels to Euler diagram. #70

JustGitting opened this issue Jun 26, 2020 · 3 comments

Comments

@JustGitting
Copy link

JustGitting commented Jun 26, 2020

Thanks for your work, it's a very useful package.

I'd like to add extra-text/labels to euler plots, so that I can provide summary information for each sub-group.
Below is a mock-up of the idea.

euler_with_labels

I understand this would be non-trivial to automatically position the extra labels, but hope there is a work around.

Here is some example code on how to generate the sub group summary numbers (not used for the above mock-up image).

df <- data.frame( id = 1:12,
                  height = runif(12, min = 100, max = 150),
                  age = runif(12, min = 3, max = 50),
                  A = c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                  B = c(0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))


group_lookup <- data.frame(A = c(0, 1, 1), 
                           B = c(1, 0, 1),
                           label = c('B', 'A', 'AnB'))


df <- df %>%
  left_join(group_lookup, by = c('A', 'B'))


group_summary <- df %>%
  group_by(label) %>%
  summarise(ave_age = mean(age),
            ave_height = mean(height))


# euler_data <- euler(c(A = 1, B = 4, "A&B" = 1))
euler_data <- euler(df[, c('A','B')])

p <- plot(euler_data)

# Add extra labels to plot or via eulerr functions?

Best wishes.

@jw5
Copy link

jw5 commented Jan 14, 2021

Rather than attempting generic labeling inside the plot routine, perhaps the euler object could be augmented with an array of set intersection locations (centers?) for use adding labels to the plot afterward. Alternately, there could be a new helper function that took the euler object and returned an array/data_frame of labeled (sets intersected) and locations.

@jw5
Copy link

jw5 commented Mar 28, 2021

It seems to me that there are two separate parts.

  1. Identifying the locations of the intersections (already done).
  2. Providing pretty user labels for selected intersections.

The current SW already does #1. #2 could be accomplished in a variety of ways. Either within or outside of the Euler diagram SW. One well accepted solution for labeling dense points with no label overlaps uses a physical simulation with the labels repelling each other. An example can be found here https://github.com/slowkow/ggrepel. This would provide a reasonable solution for automatic labeling within Euler. Alternately, a data frame of intersections and their locations could be returned and the user would be responsible for adding a new layer to the plot.

@jolars
Copy link
Owner

jolars commented Mar 28, 2021

eulerr is by the way already using a modification of the ggrepel algorithm for overlapping labels, but it works so-so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants