jimjam-slam / ggflags Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ellisp/ggflags
A flag geom for ggplot2. Tweaks the original by using round flags (great for plotting as points).
This project forked from ellisp/ggflags
A flag geom for ggplot2. Tweaks the original by using round flags (great for plotting as points).
I am running your sample code:
set.seed(1234)
d <- data.frame(x=rnorm(50), y=rnorm(50),
country=sample(c("ar","fr", "nz", "gb", "es", "ca"), 50, TRUE),
stringsAsFactors = FALSE)
ggplot(d, aes(x=x, y=y, country=country, size=x)) +
geom_flag() +
scale_country() +
scale_size(range = c(0, 15))
but I get this error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘grobify’ for signature ‘"NULL"’
My session info:
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=it_IT.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=it_IT.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=it_IT.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 xml2_1.1.1 magrittr_1.5 munsell_0.4.3 uuid_0.1-2 colorspace_1.3-2
[7] R6_2.2.2 jpeg_0.1-8 rlang_0.1.6 grImport2_0.1-4 plyr_1.8.4 tools_3.4.3
[13] grid_3.4.3 gtable_0.2.0 png_0.1-7 rvg_0.1.7 R.oo_1.21.0 ggiraph_0.4.2
[19] ggflags_0.0.2 htmltools_0.3.6 lazyeval_0.2.0 digest_0.6.12 tibble_1.4.2 zip_1.0.0
[25] officer_0.2.0 base64enc_0.1-3 htmlwidgets_0.9 R.utils_2.6.0 ggrepel_0.7.0 labeling_0.3
[31] compiler_3.4.3 pillar_1.1.0 gdtools_0.1.6 scales_0.5.0 R.methodsS3_1.7.1 XML_3.98-1.9
Hi.
Are you planning on adding support for the newest 3.6 version? I'm loving the package so far and would love to get it to work with the latest release.
Thanks,
Stefan
I'm using this to install ggflags:
devtools::install_github("rensa/ggflags")
This is the error message I get:
` √ checking for file 'C:\Users\Cesar Augusto Galvão\AppData\Local\Temp\RtmpSmDcvg\remotesb085dfc42bb\rensa-ggflags-401494a/DESCRIPTION' ...
I'm sorry I'm reaching out to you, I can`t seem to find anyone else having this problem.
A logical extension of this package would be a geom that renders an arbitrary set of icons, specified by supplying a named vector of paths to a scale like:
my_icons = c(
'soccer' = 'icons/soccer.svg',
'rugby' = 'icons/rugby.svg',
'basketball' = 'icons/basketball.svg')
sportevents = ggplot(data) +
geom_icon(aes(x = longitude, y = latitude, size = interest, icon = sport)) +
scale_icon(values = my_icons)
This would be similar to the way custom colour scales are implemented. I think this could be done either with rastered PNG icons, building on baptiste/ggflags, or with vector SVG icons if I implemented #1.
Just a quick question. Many thanks.
Kosovo has ISO3Code of XKX and ISO2Code of XK
Hi,
I would like to contribute to ggflags by adding icons for french town using their IATA and doing the pictures myself
Is it possible ?
The plotly
package doesn't, and probably cannot, support ggflags
. But ggiraph
can! It currently works fine with the output, but the flags aren't interactive at all.
I propose geom_flag_interactive
based on geom_point_interactive
. Not sure how well it'll go with package access, but we can give it a try!
https://github.com/davidgohel/ggiraph/blob/master/R/geom_point_interactive.R
The EmojiOne flag dataset has been frozen for a while now, and we've had some issues with inaccurate flags (eg. PR #16 fixes #14 and #7). https://github.com/HatScripts/circle-flags looks like it's had more recent updates and is MIT licensed.
It should point to the French flag.
Hello, wondering if you could help me. I have managed to use the package fine, but when it comes to plotting, the flags are rectangular, not circular. I was wondering if I was doing anything wrong on my end.
Code is here:
ggplot(bundesliga_gca_2022_league, aes(x = GCA90_GCA, y = SCA90_SCA, country = nationality)) +
geom_flag() +
scale_size(range = c(0, 5)) +
geom_hline(yintercept = mean(bundesliga_gca_2022_league$SCA90_SCA)) +
geom_vline(xintercept = mean(bundesliga_gca_2022_league$GCA90_GCA))
Hi there,
I used your wonderful package to produce a plot that went viral on Twitter.
Dutch people are complaining that the NL flag is actually the Luxembourg flag. See for instance here: https://twitter.com/reinier_boon/status/1601625443530334208?s=20&t=n53cl8O-LT0uz27vCy0iOw
I realized the same lighter-blue-where-darker-blue-should-have-been problem is there for France too.
And nothing, just raising this here as I have no way of fixing this downstream.
Thank you for your work!
Not sure if this is possible if they're basically equivalent to geom_point
... I can theoretically load in an alternate set of SVGs that have strokes hard-coded into them, but when I tried to do it with <circle>
elements, convertPicture
didn't like them. Plus, it'd be neat to do custom strokes without fiddling about.
I suppose if I'm desperate I could add a separate, slightly larger geom_point
behind the flags... can't jitter unless I do it manually then, though :/
But I can't seem to see if/where country code data are included in the package as structured data that can be used, so you might include this code in the vignette/main package examples page for people:
library(rvest)
url<-"http://www.nationsonline.org/oneworld/country_code_list.htm"
xpath<-"//*[@id="codelist"]"
country_codes<-url %>%
read_html() %>%
html_nodes(xpath='//*[@id="codelist"]') %>%
html_table()
country_codes
but if they're already there and I didn't look hard enough, I apologize!
Reported by a user:
set.seed(1234)
d <- data.frame(
x = rnorm(50),
y = rnorm(50),
country = sample(c("ar","fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
stringsAsFactors = FALSE)
ggplot(d, aes(x = x, y = y, country = country, size = x)) +
geom_flag() +
scale_country() +
scale_size(range = c(0, 15))
Error in class(grobs) <- "gList" : attempt to set an attribute on NULL
Currently, trying to use an invalid country results in:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘grobify’ for signature ‘"NULL"’
This is... not super helpful.
I am trying to integrate ggflags
within another package, but so far I am reaching some difficulties. Even though I refer to the function by namespace (ggflags::geom_flag
), I am getting errors relating to the inability to find underlying functions with no namespace.
Reprex for not finding ggplot2::layer
:
test_flags <- function(data) {
p <-
ggplot2::ggplot(data, ggplot2::aes(.data$x, .data$y, country = .data$country)) +
ggflags::geom_flag(size = 8.5)
p
}
set.seed(1234)
d <- data.frame(
x = rnorm(50), y = rnorm(50),
country = sample(c("ar", "fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
stringsAsFactors = FALSE
)
test_flags(d)
#> Error in layer(geom = GeomFlag, mapping = mapping, data = data, stat = stat, : could not find function "layer"
Created on 2023-09-10 with reprex v2.0.2
Even when adding ggplot2::layer
, we are faced with another error about the Geom
object not being found:
layer <- ggplot2::layer
test_flags <- function(data) {
p <-
ggplot2::ggplot(data, ggplot2::aes(.data$x, .data$y, country = .data$country)) +
ggflags::geom_flag(size = 8.5)
p
}
set.seed(1234)
d <- data.frame(
x = rnorm(50), y = rnorm(50),
country = sample(c("ar", "fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
stringsAsFactors = FALSE
)
test_flags(d)
#> Error in eval(`_inherit`, env, NULL): object 'Geom' not found
Created on 2023-09-10 with reprex v2.0.2
When I look at the code, I indeed do not see where the Geom
object is defined... But I think it refers to ggplot2::Geom
, so adding that, we still cannot find object '.flaglist'
:
layer <- ggplot2::layer
Geom <- ggplot2::Geom
test_flags <- function(data) {
p <-
ggplot2::ggplot(data, ggplot2::aes(.data$x, .data$y, country = .data$country)) +
ggflags::geom_flag(size = 8.5)
p
}
set.seed(1234)
d <- data.frame(
x = rnorm(50), y = rnorm(50),
country = sample(c("ar", "fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
stringsAsFactors = FALSE
)
test_flags(d)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'grobify': object '.flaglist' not found
Created on 2023-09-10 with reprex v2.0.2
And this time I cannot retrace what package it comes from.
Even using @import ggflags
, we are faced with another error:
#' @title Generate a waffle plot made of country flags
#' @param df The processed dataframe of data
#' @export
#' @examples
#' set.seed(1234)
#' d <- data.frame(
#' x = rnorm(50), y = rnorm(50),
#' country = sample(c("ar", "fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
#' stringsAsFactors = FALSE
#' )
#' test_flags(d)
#' @import ggflags
test_flags <- function(data) {
p <-
ggplot2::ggplot(data, ggplot2::aes(.data$x, .data$y, country = .data$country)) +
ggflags::geom_flag(size = 8.5)
p
}
> test_flags(d)
Error in eval(`_inherit`, env, NULL) : object '`_inherit`' not found
Similar result by loading ggflags
' namespace:
requireNamespace("ggflags")
#> Loading required namespace: ggflags
layer <- ggplot2::layer
Geom <- ggplot2::Geom
test_flags <- function(data) {
p <-
ggplot2::ggplot(data, ggplot2::aes(.data$x, .data$y, country = .data$country)) +
ggflags::geom_flag(size = 8.5)
p
}
set.seed(1234)
d <- data.frame(
x = rnorm(50), y = rnorm(50),
country = sample(c("ar", "fr", "nz", "gb", "es", "ca", "lv", "qa"), 50, TRUE),
stringsAsFactors = FALSE
)
test_flags(d)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'grobify': object '.flaglist' not found
Created on 2023-09-10 with reprex v2.0.2
The only solution seems to literally load ggflags
with library(ggflags)
, but of course this is not recommended practice and will not be eventually accepted on e.g., CRAN. Any idea how to fix this on my side?
The flag grobs aren't bounded by the plotting area the way other geom grobs (like pointsGrob
) are. This appears in the Rstudio rendering device, and in all of the ggplot2::ggsave
devices I tested (PDF and PNG). However, it doesn't appear when I save to SVG using gridSVG::grid.export
: in that case, the flags are properly bounded by the plotting area.
This doesn't affect the pointsGrob
I'm using as an outline for the flags: even if the flags themselves spill over, the outlines stop at the edge.
This is mostly noticeable because the plotting area is calculated based on the position of geoms, not their size (at least not for geom_flag
and geom_point
. So if you're using appreciable sizes, it makes sense to expand the plotting domain.
baptiste/ggflags plots PNGs, which is fine if you just want the points positioned but not sized. But if you decide to make big points, or bind flag size to an aesthetic, you either need bigger PNGs (in which case the package size blows out), or you need to accept poor image quality.
I'd prefer to plot SVGs, especially as most of the open source emoji sets like EmojiOne and Twemoji have SVG assets available. I think this can be done by pre-processing the SVGs to be Cairo-compatible with grConvert
and then rendering them with grid.symbol()
or grid.picture()
. Maybe grobify()
?
This was mentioned in #9, and a mechanism was proposed. I want to give this some thought for v1.0 first, so no promises!
Hi @Rensa,
It seems like the Latvian flag (lv) has the wrong colors. It has kind of purple stripes but these should be dark red. I tried to modify the Rdata file to fix it, but it was a bit more complicated than expected. Perhaps you can take a look at it at some point?
Thanks in advance,
Martin
Warning in install.packages :
package ‘ggflags’ is not available (for R version 3.6.2)
I'm trying to install the package and I get the warning that it is not available on CRAN. "Warning in install.packages :
package ‘ggflags’ is not available (for R version 4.0.2)". Can I still install it from Github using remotes/devtools?
Hi, really love the looks of this package and would love to use it for some graphing I am doing (especially the flag scaling!). I keep getting the following error when I tried to run the example:
Error in download_url(path) : Failed to download https://behdad.github.io/region-flags/png//Library/Frameworks/R.framework/Versions/3.5/Resources/library/ggimage/extdata/Rlogo.png.png (HTTP 404)
Any suggestions?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.