ggplot labels with linebreaks inn ggvenn venn diagram
0
0
Entering edit mode
@anderstondell-9441
Last seen 10 months ago

Hi,

I have a problem with the labels on a ggvenn venn diagram. I would like to be able to display labels on multiple lines, one line pr. item, which is better if working with large lists/long character vectors. Please see example below.

library(ggvenn)
d<-data.frame(id=paste(LETTERS[1:9]),
A=c(TRUE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,FALSE,FALSE),
B=c(FALSE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE),
C=c(FALSE,FALSE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,FALSE))

p<-ggplot(d) +
geom_venn(aes(A=A,B=B,C=C,label=id)) +
coord_fixed()
theme_void()
p#Labels are displayed on one line for each intersection, sep=","..
#I would like labels to be separated by sep/collapse(?)="\n"

p<-ggplot(d) +
geom_venn(aes(A=A,B=B,C=C,label=paste(id, collapse = "\n"))) +
coord_fixed()
theme_void()
p#Does not work...


Any help would be appreciated!

With regards,

ggvenn ggplot2 • 544 views
0
Entering edit mode

Adding this line after after you make the data frame (e.g. before ggplot) makes it a little better:

d$id <- paste0(d$id, "\n")

But still gives labels with annoying leading commas

0
Entering edit mode

Hey anders.tondell, please keep in mind that ggvenn is not a Bioconductor package. So, you may get a quicker response by posting on the GitHub issues page for ggvenn, or reaching out to the developers in some other way.

0
Entering edit mode

Thanks for help and comments, eugene100hickey and Kevin Blighe! The problem is solved. Package developer Linlin Yan answered my request, see below:

"Yes, there was no quick fix for your answer, since I hard-coded collapse = "," in the previous version. So, I updated a new version (0.1.5, https://github.com/yanlinlin82/ggvenn/releases/tag/v0.1.5). More detail could be found at https://github.com/yanlinlin82/ggvenn/issues/9.

You may upgrade to this latest version, and try 

ggplot(d) +
geom_venn(aes(A=A,B=B,C=C,label=id), label_sep = "\n")


or 

ggvenn(d,
show_elements = "id",  label_sep = "\n")
`

"