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

fill and fontface otions for geom_gene_label #141

Closed
minalj365 opened this issue Feb 3, 2023 · 4 comments
Closed

fill and fontface otions for geom_gene_label #141

minalj365 opened this issue Feb 3, 2023 · 4 comments

Comments

@minalj365
Copy link

Hello!

I want to color gene labels with the same colors as geom_gene (I have "geom_gene(aes(label=gene))"). Also, I want gene labels in italics.
fill and fontface are not working for geom_gene_label. Can you please recommend a way?

Thank you,
Minal

@thackl
Copy link
Owner

thackl commented Feb 3, 2023

This works for me. If you mean something else, please provide an example.

g0 <- tibble(seq_id="a", start=10, end=500, gene="foo")
gggenomes(g0) +
  geom_gene(aes(fill=gene)) +
  geom_gene_label(aes(label=gene, color=gene), fontface="italic", show.legend=FALSE)

image

@minal033
Copy link

minal033 commented Feb 3, 2023

Yes, that worked! Thank you so much! Now encountering a different problem though. Some of the genes are pseudogenes so I use greek psi symbol to label them. Before color and fontface, plot was showing psi symbol but now it shows some strange character instead of psi. I tried a couple of online solutions to convert encoding into UTF-8 but no success yet. Please let me know if you have a solution that can work. Here is a screenshot of the table that I read in R:
image

@thackl
Copy link
Owner

thackl commented Feb 3, 2023

Hm, strange. I cannot reproduce this on my system, see below.

# thought this would work with `parse=T` but got no character for psi at all
g0 <- tibble(
  seq_id="a", start=c(10, 600), end=c(500, 1000),
  # this seems to work just fine
  gene=c("foo", "ψ"),
  # thought this would work with `parse=T` 
  # but got no character for psi at all
  gene_parse=c("foo", "psi"),
  # unicode seems to work as well
  gene_unicode=gsub("ψ", "\u03C8", gene)
)

gggenomes(g0) +
  geom_gene(aes(fill=gene)) +
  # psi and italic
  geom_gene_label(aes(label=gene, color=gene), 
                  fontface="italic", show.legend=F, nudge_x=-100) +
  # no psi, and not italic
  geom_gene_label(aes(label=gene_parse, color=gene), 
                  fontface="italic", show.legend=F, parse=T) +
  # psi and italic
  geom_gene_label(aes(label=gene_unicode, color=gene),
                  fontface="italic", show.legend=F, nudge_x=100)

image

@minalj365
Copy link
Author

Thank you for trying this! Your solution works for me but only when I write a tibble. In my case, I have to read a table. I found out that if I save the file with .txt, and read with read.delim(), then psi is labeled as a greek letter on the plot. Other extensions like .tsv, .csv, .xlsx don't work!

@thackl thackl closed this as completed Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants