Grokbase Groups R r-help June 2016
FAQ
Hi all,
I want to use world map in ggplot2 and show my data on world map. my df is:




     $ COUNTRY : chr "DE" "DE" "FR" "FR" ..


     $ ContrastColor : int 9 9 9 9 13 9 9 9 9 ..


     $ quant : Factor w/ 4 levels "FAST","SLOW",..I need to merge my df with world_map data which is like this:




     world_map=map_data("world")
     data.frame': 99338 obs. of 6 variables:
     $ long : num -69.9 -69.9 -69.9 -70 -70.1 ...
     $ lat : num 12.5 12.4 12.4 12.5 12.5 ...
     $ group : num 1 1 1 1 1 1 1 1 1 1 ...
     $ order : int 1 2 3 4 5 6 7 8 9 10 ...
     $ region : chr "Aruba" "Aruba" "Aruba" "Aruba" ...
     $ subregion: chr NA NA NA NA ...
but by merging my df with world map data I get a data frame with zero observation in it,I use this command for merging:




     world_map=merge(world_map,df,by.x="region",by.y="COUNTRY")
     str(world_map)


     'data.frame': 0 obs. of 133 variables:
     $ region : chr
     $ long : num
     $ lat : num
     $ group : num
     $ order : int
     $ subregion : chr
does anyone know what is the problem of this merging that I am currently using?
thanks for any help!
Elahe

Search Discussions

  • Jeff Newmiller at Jun 17, 2016 at 8:21 pm
    You should look at your own data before you post. The information in COUNTRY is not the same as the information in region.


    Also, dput is better than str for posting questions.
    --
    Sent from my phone. Please excuse my brevity.

    On June 17, 2016 1:06:29 PM PDT, "ch.elahe via R-help" wrote:
    Hi all,
    I want to use world map in ggplot2 and show my data on world map. my df
    is:


    $ COUNTRY : chr "DE" "DE" "FR" "FR" ..

    $ ContrastColor : int 9 9 9 9 13 9 9 9 9 ..

    $ quant : Factor w/ 4 levels "FAST","SLOW",..I need to
    merge my df with world_map data which is like this:


    world_map=map_data("world")
    data.frame': 99338 obs. of 6 variables:
    $ long : num -69.9 -69.9 -69.9 -70 -70.1 ...
    $ lat : num 12.5 12.4 12.4 12.5 12.5 ...
    $ group : num 1 1 1 1 1 1 1 1 1 1 ...
    $ order : int 1 2 3 4 5 6 7 8 9 10 ...
    $ region : chr "Aruba" "Aruba" "Aruba" "Aruba" ...
    $ subregion: chr NA NA NA NA ...
    but by merging my df with world map data I get a data frame with zero
    observation in it,I use this command for merging:


    world_map=merge(world_map,df,by.x="region",by.y="COUNTRY")
    str(world_map)

    'data.frame': 0 obs. of 133 variables:
    $ region : chr
    $ long : num
    $ lat : num
    $ group : num
    $ order : int
    $ subregion : chr
    does anyone know what is the problem of this merging that I am
    currently using?
    thanks for any help!
    Elahe

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

      [[alternative HTML version deleted]]
  • David Winsemius at Jun 17, 2016 at 8:22 pm

    On Jun 17, 2016, at 1:06 PM, ch.elahe via R-help wrote:

    Hi all,
    I want to use world map in ggplot2 and show my data on world map. my df is:


    $ COUNTRY : chr "DE" "DE" "FR" "FR" ..

    $ ContrastColor : int 9 9 9 9 13 9 9 9 9 ..

    $ quant : Factor w/ 4 levels "FAST","SLOW",..I need to merge my df with world_map data which is like this:


    world_map=map_data("world")
    data.frame': 99338 obs. of 6 variables:
    $ long : num -69.9 -69.9 -69.9 -70 -70.1 ...
    $ lat : num 12.5 12.4 12.4 12.5 12.5 ...
    $ group : num 1 1 1 1 1 1 1 1 1 1 ...
    $ order : int 1 2 3 4 5 6 7 8 9 10 ...
    $ region : chr "Aruba" "Aruba" "Aruba" "Aruba" ...
    $ subregion: chr NA NA NA NA ...
    but by merging my df with world map data I get a data frame with zero observation in it,I use this command for merging:


    world_map=merge(world_map,df,by.x="region",by.y="COUNTRY")
    str(world_map)

    'data.frame': 0 obs. of 133 variables:
    $ region : chr
    $ long : num
    $ lat : num
    $ group : num
    $ order : int
    $ subregion : chr
    does anyone know what is the problem of this merging that I am currently using?
    thanks for any help!

    I would not expect a merger based on the one hand on two letter initials to match on the other hand fully spelled-out country names.




    --


    David Winsemius
    Alameda, CA, USA
  • MacQueen, Don at Jun 17, 2016 at 9:08 pm
    And you can check what David and Jeff suggested like this:


    intersect( df$COUNTRY, world_map$region )


    If they have any values in common, that command will show them. (Note that
    I said values in common, not countries in common.)


    WARNING:
    It appears that you have each country appearing more than once in both of
    the data frames. Even if the country names were spelled the same (which
    they are not in the first few rows), I would not care to predict the
    outcome of a many-to-many merge. It probably won't make sense for showing
    the data on a map.


    -Don


    --
    Don MacQueen


    Lawrence Livermore National Laboratory
    7000 East Ave., L-627
    Livermore, CA 94550
    925-423-1062










    On 6/17/16, 1:06 PM, "R-help on behalf of ch.elahe via R-help"
    <r-help-bounces@r-project.org on behalf of r-help@r-project.org> wrote:

    Hi all,
    I want to use world map in ggplot2 and show my data on world map. my df
    is:


    $ COUNTRY : chr "DE" "DE" "FR" "FR" ..

    $ ContrastColor : int 9 9 9 9 13 9 9 9 9 ..

    $ quant : Factor w/ 4 levels "FAST","SLOW",..I need to
    merge my df with world_map data which is like this:


    world_map=map_data("world")
    data.frame': 99338 obs. of 6 variables:
    $ long : num -69.9 -69.9 -69.9 -70 -70.1 ...
    $ lat : num 12.5 12.4 12.4 12.5 12.5 ...
    $ group : num 1 1 1 1 1 1 1 1 1 1 ...
    $ order : int 1 2 3 4 5 6 7 8 9 10 ...
    $ region : chr "Aruba" "Aruba" "Aruba" "Aruba" ...
    $ subregion: chr NA NA NA NA ...
    but by merging my df with world map data I get a data frame with zero
    observation in it,I use this command for merging:


    world_map=merge(world_map,df,by.x="region",by.y="COUNTRY")
    str(world_map)

    'data.frame': 0 obs. of 133 variables:
    $ region : chr
    $ long : num
    $ lat : num
    $ group : num
    $ order : int
    $ subregion : chr
    does anyone know what is the problem of this merging that I am currently
    using?
    thanks for any help!
    Elahe

    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedJun 17, '16 at 8:06p
activeJun 17, '16 at 9:08p
posts4
users4
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase