jolars / eulerr

Area-Proportional Euler and Venn Diagrams with Ellipses
https://jolars.github.io/eulerr/
GNU General Public License v3.0
129 stars 18 forks source link

lables still overlapping #69

Open carlotta-93 opened 4 years ago

carlotta-93 commented 4 years ago

Hi, Thank you for your amazing work, I am using your package a lot and find it very useful. I have an issue with overlapping labels. This is an example:

example_labels

As you can see the labels overlap with the percentages and counts.

I am using eulerr version 6.1.0 and this is the code I am using:

Screenshot 2020-04-20 at 11 08 04

Can you help ?

Thanks

JustGitting commented 4 years ago

Hi @carlotta-93,

I had a similar problem, but I'm not sure it's related to your situation. I tried to reproduce your example, but cannot find any "Shulse" data sets.

Can you provide a minimal reproducible example? I had to search for and install the Rknots package that provides the intersectionMatrix() function as I was not familiar with that function.

Also, I'd recommend not using images of code as it means anyone trying to help you needs to manually re-type the code.

jolars commented 4 years ago

There is certainly work to be done regarding the label repulsion features of the package. The current code for this is imported from the ggrepel package, but I think it might be a good idea to consider something different or tinker with the settings.

A concomitant issue is that the extraneous white space around the figure is not used when moving around labels, which is related to how the aspect ratio is kept fixed at the moment.

I agree that there's lots to be done here, but at the moment I do not quite have the time to do so.

carlotta-93 commented 4 years ago

Hi @JustGitting, sorry for the late reply but I wanted to make this answer as complete as possible.

So, this is the code I am using, the function I defined:

makeEulerDiagram <- function(sets_list, color_palette, plot_name, plot_title, folder){
  plot_id <- as.symbol("plot_name")
  venset <- overLapper(sets_list, type="vennsets")
  plot_id <- plot(
    euler(intersectmatrix(venset), regionError = T),

    fills = list(fill=color_palette, alpha=0.8),

    edges = list(lwd=0.3),

    labels = list(fontfamily = "sans",
                  main.fontfamily = "sans",
                  cat.fontfamily = "sans",
                  fontsize=10,
                  padding=grid::unit(10, "mm")
    ),

    legend = list(fontsize=18),

    main = list(label=plot_title,
                fontsize=12
    ),

    percentages = list(fontsize=15
    ),

    quantities = list(type=c("counts","percent"), fontsize=15),

    adjust_labels = TRUE

  )
  print(plot_id)
  ggsave(plot_id, file=paste0(folder, plot_name, ".svg"), device = "svg", width = 30, height = 30, units="in")
  ggsave(plot_id, file=paste0(folder, plot_name, ".png"), device = "png", width = 30, height = 30, units="in")
}

This is how I call it:

makeEulerDiagram(list("this_is_list_A" = list_A, 
"this_is_list_B" = list_B), 
color_palette = c("#7d5a5a", "#f1d1d1"), 
plot_name = "pf2_de_genes_proteins", 
plot_title = paste0("intersection of list A and B"), 
folder = /path_to_folder/)

you can fin the two lists here: https://www.dropbox.com/s/1bjp5hrp7wml1ed/lists_github_example.xlsx?dl=0

And for now this is the output: image

as you can see the problem is "solved" for this case, but I have many more examples, especially when intersecting more than 2 sets where the problem still persists.

For example here, it would be great if we managed to get ticks for example, going from the intersections to the labels that would be placed outside of the circles. image

This is just a suggestion and for now I solved the problem with saving an svg file and modifying in photoshop.

Also, thank @jolars for getting back at us :)

jw5 commented 3 years ago

I've found the ggrepl labeling function to be quite capable even with tight clusters.

Is it possible to provide a ggplot "plot" version?

I've pulled the ellipse definitions out and they plot fine with ggplot, but I couldn't find label locations and associated data.

jolars commented 3 years ago

I've found the ggrepl labeling function to be quite capable even with tight clusters.

Is it possible to provide a ggplot "plot" version?

I am actually using the ggrepel code here, albeit not the latest revision. One of the problems is that I haven't been able to find a good way to use the whitespace on the left of the plot for moving labels (when there is whitespace).

I've pulled the ellipse definitions out and they plot fine with ggplot, but I couldn't find label locations and associated data.

Is this what you're looking for?

library(eulerr)

p <- plot(euler(c(A = 1, B = 2, "A&B" = 0.2)), quantities = TRUE)
p$data$centers
#>              x             y id labels quantities labels_par_id
#> A   -0.8141626 -3.167287e-02  1      A        1.0             1
#> B    0.6399415  3.100711e-02  2      B        2.0             2
#> A&B -0.1964353  1.638883e-05  3   <NA>        0.2            NA
#>     quantities_par_id
#> A                   1
#> B                   2
#> A&B                 3

Created on 2021-01-14 by the reprex package (v0.3.0)