Giter Site home page Giter Site logo

jimjam-slam / ggflags Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ellisp/ggflags

91.0 91.0 14.0 42.46 MB

A flag geom for ggplot2. Tweaks the original by using round flags (great for plotting as points).

R 100.00%
dataviz flags ggplot2 ggplot2-enhancements r rstats

ggflags's People

Contributors

baptiste avatar jimjam-slam avatar maelle avatar rempsyc avatar richardmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ggflags's Issues

Method for 'grobify' missing

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

Supporting R version 3.6

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

Won't install Description

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' ...

  • preparing 'ggflags':
    √ checking DESCRIPTION meta-information ...
    Warning in .write_description(db, ldpath) :
    Unknown encoding with non-ASCII data: converting to ASCII
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • looking to see if a 'data/datalist' file should be added
  • building 'ggflags_0.0.2.tar.gz'
  • installing source package 'ggflags' ...
    Error in file(file, if (append) "a" else "w") :
    (converted from warning) cannot open file 'C:/Users/Cesar Augusto Galvco/Documents/R/win-library/3.5/ggflags/DESCRIPTION': No such file or directory
    ERROR: installing package DESCRIPTION failed for package 'ggflags'
  • removing 'C:/Users/Cesar Augusto Galvão/Documents/R/win-library/3.5/ggflags'
    In R CMD INSTALL `

I'm sorry I'm reaching out to you, I can`t seem to find anyone else having this problem.

Render arbitrary sets of icons

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.

Contribute to ggflags projects

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 ?

Flags are rectangular, not circular

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.

c76fab99-4e21-4789-8e78-ecbb4f46dbef

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))

"wrong" hue of blue for France and the Netherlands

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!

Dynamically add a stroke to the flags

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 :/

Maybe I just couldn't find them

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!

Compatibility with R 4.2

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

Several errors when attempting to integrate with other packages

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?

Flags spilling over plot area

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.

Plot SVGs (or another vector format) instead of PNGs

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()?

Wrong flag

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

Package ‘ggflags’ is not available (for R version 4.0.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?

Failed download error

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.