0

I am trying to make a string in R containing both standard letters and a symbol beside. I notice that R seems to print strictly UTF-8 symbols only. So non-standard letters and even emojis. However when it comes to flags it will only print the letters of the flag. Preferably only a label on a graph such as geom_text.

# Name
"<Jamaican Flag> Usain Bolt"

# Emoji
cat(paste("\U0001f600", "Usain Bolt"))

# Flag
cat(paste("\U1F1EF\U1F1F2", "Usain Bolt"))

What I want ideally is something like this which I produced on Facebook messenger:

enter image description here

Any ideas? Thanks.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
user3456588
  • 609
  • 4
  • 9
  • yes but if you run the example R has no problem converting the UTF8 to a real emoji. Why not flags? And the link you sent still only output 'JM' when running the code. – user3456588 Dec 13 '19 at 11:04
  • R writes *text* to the output, eg file or console, not images. How that text appears depends on the font used by the console, terminal, or text viewer. You need to use a font that contains glyphs for those emojis. – Panagiotis Kanavos Dec 13 '19 at 11:05
  • `converting the UTF8 to a real emoji.` there's no real emoji and no conversion. The bytes in the string are rendered using the glyphs in the font. If there's no matching glyph, nothing is displayed. If you got a sequence that's only valid on Facebook's custom fonts, you won't be able to render it without that font. You need to check a list of emojis and the OSs, browsers, fonts that support them – Panagiotis Kanavos Dec 13 '19 at 11:07
  • You didn't mention the most important thing. Where are you trying to display that text? Browser? RStudio? Text editor? – Panagiotis Kanavos Dec 13 '19 at 11:08
  • Sorry I'll add it to the question, I am trying to add it to geom_text as a label on ggplot2. Is there a way to download new glyphs for R? – user3456588 Dec 13 '19 at 11:14
  • So the *real* question is how to display emojis in ggplot2 – Panagiotis Kanavos Dec 13 '19 at 11:18
  • Another related question: https://stackoverflow.com/questions/52493638/plot-emoji-custom-image-in-axis-labels-in-r – Panagiotis Kanavos Dec 13 '19 at 11:21
  • I think it does, I did have a look at emoji package before and don't think it had flags but I might be mistaken. It gives me something to move from at least. Thanks. – user3456588 Dec 13 '19 at 11:22

0 Answers0