jimjam-slam / ggflags

A flag geom for ggplot2. Tweaks the original by using round flags (great for plotting as points).
92 stars 15 forks source link

Failed download error #9

Closed cdkuempel closed 2 years ago

cdkuempel commented 5 years ago

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!

jimjam-slam commented 5 years ago

Hi @cdkuempel! That's concerning. I need to fix another issue that's a little overdue, so can I get back to you in a couple of days on this?

jimjam-slam commented 5 years ago

Actually, are you able to give me a little more context on this? When you say "run the example", do you literally mean when you run this statement?

ggplot(d, aes(x=x, y=y, country=country, size=x)) + 
  geom_flag() + 
  scale_country() +
  scale_size(range = c(0, 15))

Or is this error occurring when you install or load the package?

Thanks!

cdkuempel commented 5 years ago

Hi, thanks for your response!

Yes - I tried running:

library(ggflags)

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

Within my existing script and I still get the error. However, I just tried running it in a new Rmd file and it worked as expected. Maybe it is getting confused in my existing script with another package? (it looks like ggimage also has a geom_flag call) but even after I remove the ggimage package I get the same error. Not sure what is happening - maybe I will play around with a new script next week and see if I can solve the problem. I will post an update if I do!

jimjam-slam commented 5 years ago

It's certainly possible! The flag images in ggflags are all self-contained (I build and bundle them with the package), so it shouldn't be making any external requests. If you can run sessionInfo() or devtools::session_info() when the error comes up, we can see what else you have loaded and see what might be causing the problem 🙂

EDIT: even better, the conflicted package can tell you if two packages have the same name and are interfering with each other!

cdkuempel commented 5 years ago

Great thanks - it did come up with a geom_flag conflict between ggimage and ggflags but I set conflict_prefer to always use ggflags.

The example still works, but I still get an error when trying to use it with my own data - which is the same error as #6

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘grobify’ for signature ‘"NULL"’

sessionInfo():

R version 3.5.1 (2018-07-02) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS 10.14.6

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] conflicted_1.0.4 scales_1.0.0 countrycode_1.00.0 gridExtra_2.3 ggrepel_0.8.0
[6] stringr_1.4.0 ggflags_0.0.2 RColorBrewer_1.1-2 dplyr_0.8.3 tidyr_1.0.0
[11] here_0.1 ggpubr_0.2.3 magrittr_1.5 ggplot2_3.2.1 rworldmap_1.3-6
[16] sp_1.3-1 data.table_1.12.2 sf_0.7-3

loaded via a namespace (and not attached): [1] spam_2.2-0 tidyselect_0.2.5 xfun_0.5 grImport2_0.1-5 purrr_0.3.2
[6] lattice_0.20-35 colorspace_1.4-1 vctrs_0.2.0 yaml_2.2.0 base64enc_0.1-3 [11] XML_3.98-1.20 rlang_0.4.0 e1071_1.7-0.1 pillar_1.4.2 foreign_0.8-70
[16] glue_1.3.1 withr_2.1.2 DBI_1.0.0 jpeg_0.1-8 lifecycle_0.1.0 [21] fields_9.6 dotCall64_1.0-0 munsell_0.5.0 ggsignif_0.4.0 gtable_0.3.0
[26] memoise_1.1.0 labeling_0.3 knitr_1.22 maptools_0.9-5 class_7.3-14
[31] Rcpp_1.0.2 backports_1.1.4 classInt_0.3-1 digest_0.6.20 png_0.1-7
[36] stringi_1.4.3 grid_3.5.1 rprojroot_1.3-2 tools_3.5.1 maps_3.3.0
[41] lazyeval_0.2.2 tibble_2.1.3 crayon_1.3.4 pkgconfig_2.0.2 zeallot_0.1.0
[46] ellipsis_0.2.0.1 assertthat_0.2.1 rstudioapi_0.8 R6_2.4.0 units_0.6-2
[51] compiler_3.5.1

It says ggflags is attached - any other suggestions?

jimjam-slam commented 5 years ago

Hmm, that's interesting. Are you able to show me your plotting code, as well as a snippet (say the head() of the data frame you're plotting?

jimjam-slam commented 5 years ago

Sorry, I should elaborate a little. I'm particularly interested in the type of data you're passing as the country aesthetic—it only occurs to me now (since I didn't work on the documentation when I forked this package) that, as a spatial user, you might be trying to pass geo columns like sf polygons directly.

If that's not the case, I might need to go bug hunting 😅

cdkuempel commented 5 years ago

Ahhh that was it! I was using ISO3 codes so changed it to lower case iso2. I also disabled the legend (theme(legend.position = "none") and then it worked!!

Thanks so much for your quick responses - it made the trouble shooting much more pleasant than struggling on my own!

jimjam-slam commented 5 years ago

Struggling on your own always sucks! Glad I could help 😄

I'll keep this issue open, 'cause I believe ggplot2 3.0 introduced new options around legend glyphs that aren't taken into account in ggflags (whenever I've tested it, it's just used an NZ flag as the glyphs). it's possible this is also causing problems. And the docs should more explicitly state the data required!

mertcank1 commented 3 years ago

I guess, this web site path is not correct so it gives error. I share something in below. I tried it. and it hasnt problem. you can reach this web site(https://mran.microsoft.com/snapshot/2017-03-16/web/packages/ggimage/README.html)

ggflags cn <- "https://behdad.github.io/region-flags/png/CN.png" fr <- "https://behdad.github.io/region-flags/png/FR.png" us <- "https://behdad.github.io/region-flags/png/US.png"

set.seed(123) d$image <- sample(c(cn, fr, us), size=nrow(d), replace=TRUE) ggplot(d, aes(x, y)) + geom_image(aes(image=image))

jimjam-slam commented 3 years ago

Very tempted to rewrite ggflags to use ggimage, actually! Or perhaps even fold the functionality right into ggimage, given it already has geom_emoji and geom_flag (that uses PNGs, I think), as well as SVG support. It might be better to update that function to use round SVGs. (I know some folks prefer the original flag aspect ratios; I prefer round because then you can use them for bubble plots).

mertcank1 commented 3 years ago

thank you very much for your recommend, I will try.

mertcank1 commented 3 years ago

immediately I tried it. library(ggplot2) library(ggimage) library(rsvg)

cn <- "https://hatscripts.github.io/circle-flags/flags/cn.svg" fr <- "https://hatscripts.github.io/circle-flags/flags/fr.svg" us <- "https://hatscripts.github.io/circle-flags/flags/us.svg"

set.seed(123) d$image <- sample(c(cn, fr, us), size=nrow(d), replace=TRUE) ggplot(d, aes(x, y)) + geom_image(aes(image=image))