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
Add Unicode symbols (emoji flags) #225
Add Unicode symbols (emoji flags) #225
Conversation
Fixes #224 |
Ha! This is cool. Thanks @NilsEnevoldsen! cat(countrycode('Germany', 'country.name', 'unicode.symbol'))
#> π©πͺ |
Yeah, this is very cool! I think it might be nice to add this to the README because it's a cute "showy" feature. Does anyone know how to render flags in a plot? I'm thinking of something like this: library(countrycode)
countries <- c('Canada', 'Germany', 'Thailand')
flags <- countrycode(countries, 'country.name', 'unicode.symbol')
barplot(1:3, names.arg = flags) But this only shows me emptys squares instead of the flags. |
R graphics devices are pretty bad with Unicode, so I have mixed feelings about talking this feature up too much. If you export the graph to an SVG and display the graph with, say, a web browser, it should work better. Maybe Unicode fonts work better with Shiny? (I don't know; I haven't used Shiny much.) library(ggplot2)
library(gridSVG)
ggplot() + annotate("text", x = 0, y = 0, label = "π¦πΆ", size = 32)
grid.export("emoji.svg") Even Unicode on the command prompt can depend on the OS. Here's what it looks like for me on macOS: > countrycode('Antarctica','country.name','unicode.symbol')
[1] "\U0001f1e6\U0001f1f6"
> countrycode('Antarctica','country.name','unicode.symbol') %>% utf8::utf8_print()
[1] "π¦πΆβ" |
@vincentarelbundock To modify your example, countries <- c('Canada', 'Germany', 'Thailand')
flags <- countrycode::countrycode(countries, 'country.name', 'unicode.symbol')
barplot(1:3, names.arg = flags)
gridGraphics::grid.echo()
gridSVG::grid.export("barplot.svg") |
Thanks @NilsEnevoldsen . I agree that this is too complicated and system-dependent for us to offer a comprehensive solution. I still think the feature is really cool, so I included a section to the README where I showcase it in a https://github.com/vincentarelbundock/countrycode#unicode-flags Thanks again! |
Excellent compromise. It does add a bit of color to the docs.
Seems reasonable. |
@vincentarelbundock Oh, if you wanted to, you could add the advice that if your output looks like As a rule of thumb, if your output looks like Up to you whether you think that's worthwhile. |
good idea. done. |
This adds Unicode region subtags as pairs of Regional Indicator Symbols. Region subtags represent regions, not flags. When composed of Regional Indicator Symbols, they are displayed as flags on most systems, but on Windows they are displayed as pairs of letters.
https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
Unicode lists valid Unicode region subtags. They are based on ISO 3166-1 alpha-2.
https://unicode.org/reports/tr51/#Flags