0

I have been working on creating a scatter plot using the ggflags packages but I've been having issues with it. There is no flags showing on my plot. I have googled the warning messages and most people say it's because either there are NAs in the data or it has something to do with y/xlim. I tried both but still not working. May be there is something else I did wrong.Can someone help me out?

Below is my code#########################################

library(ggflags)
forRegions <- read_excel("180810_60 CountriesByRegion_EpiSdgi.xlsx", 
                         sheet = "duplicate")
forRegions<- forRegions[,c(1:3)] #extract first 3 columns
oce0101 <- read_excel("EPI Analysis.xlsx", sheet = "EPI duplicate")
oce0102<- oce0101[,c(2,3,23)] #extract mpa index column 
oce0103<- merge(oce0102,forRegions,by= 'iso') #to include regions

df=data.frame(oce0103)
library(countrycode)
code=countrycode(df$country,"country.name","iso2c")
df$country=sample(c(code))
 #df[df==0]=NA
 #na.omit(df)
df <- na.omit(df)
ggplot(df,aes(x=Region,y=MPA.current,country=country,size=Region))+
  geom_flag(aes())+
  #scale_country()+
 # scale_size(range=c(0,15))+
  scale_x_discrete(limits =c(0,100))+
  scale_y_continuous(limits =c(0,110))
#
markus
  • 25,843
  • 5
  • 39
  • 58
Ke Liang
  • 1
  • 2
  • Use `coord_cartesian` instead of `scale_*_continous` to zoom into your plot. Take a look the `ggplot2` cheat sheet (second page, bottom right): https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf – markus Jan 31 '19 at 12:32
  • Related: [Explain ggplot2 warning: “Removed k rows containing missing values”](https://stackoverflow.com/questions/32505298/explain-ggplot2-warning-removed-k-rows-containing-missing-values) – markus Jan 31 '19 at 12:34
  • I did what you said but there is a new error: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘grobify’ for signature ‘"NULL"’ – Ke Liang Jan 31 '19 at 14:16
  • 2
    It's hard for us to know what exactly is going on since we don't have any of your data to be able to plot this ourselves, and don't have any of the problematic output you're trying to fix. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making a reproducible question folks can help with – camille Jan 31 '19 at 14:54

1 Answers1

0

It is difficult for us to answer this question as your code is not a reproducible example. I suspect the problem is that at least one of the country codes in your dataset does not match with the ggflags dataset.

This page here for ggflags https://github.com/rensa/ggflags/issues/10

suggests your error message is related to using invalid country codes.

I would double check your list of country codes and make sure they all match the list here:

https://github.com/rensa/ggflags

I had a similar problem in code I wrote as I mistakenly had all the country codes in UPPER CASE rather than lower case. Turning them to lower case fixed the problem.

Steven Tokar
  • 31
  • 1
  • 6