12

Running these commands in the console, the output is:

> cty0 = ggplot2::map_data("county")
> library(tidyverse)
Loading tidyverse: ggplot2
Loading tidyverse: tibble
Loading tidyverse: tidyr
Loading tidyverse: readr
Loading tidyverse: purrr
Loading tidyverse: dplyr
Conflicts with tidy packages -----------------------------------------------------------------------------------------------
filter(): dplyr, stats
lag():    dplyr, stats
map():    purrr, maps
> cty0 = ggplot2::map_data("county")
Error: ggplot2 doesn't know how to deal with data of class list

I can call map_data("county") fine until tidyverseis loaded, then it fails. How do I load a county map data with tidyverse loaded?

Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 3
    I'm guessing that the items below the dashed line are from the console messages, but you really should clarify that. Seems likely that the `map` function in 'purrr' is masking the `map` function in the 'maps' package. You could reverse the order of loading tidyverse and maps if there were a reason that you needed the (geographic notion of) "mapping" more than you needed the (functional-computer language notion of) "mapping". You probably need to start a new session for that to succeed. The `library` function checks to see of a package is already loaded and if so does nothing. – IRTFM May 26 '17 at 16:45
  • I'd mention this to the developers of tidyverse as well. – Joris Meys May 26 '17 at 18:39

1 Answers1

10

Transferred the comment from above after testing:

I'm guessing that the items below the dashed line are from the console messages , but you really should clarify that . Seems likely that the map function in 'purrr' is masking the map function in the 'maps' package. You could reverse the order of loading tidyverse and maps if there were a reason that you needed the (geographic notion of) "mapping" more than you needed the (functional-computer language notion of) "mapping". You probably need to start a new session for that to succeed. The library function checks to see of a package is already loaded and if so does nothing.

A comment on terminology. My guess is that the computer operation of "mapping" is actually a contraction from "multiple application" (of a function to interim results). If there were a chance to go back and rename it to something that would be similar to a geographic concept, it might be named route()-ing. A geographic "map" would seem to be a static two or three-dimensional object or "mapping" to be placement of positions on such an object.

Seems to succeed:

# In a fresh session (and my profile attaches ggplot2 by default)
> library(tidyverse)
Loading tidyverse: tibble
Loading tidyverse: tidyr
Loading tidyverse: readr
Loading tidyverse: purrr
Loading tidyverse: dplyr
Conflicts with tidy packages ---------------------------------
combine():   dplyr, Hmisc  # loaded in my .Rprofile; also attaches gglot2
filter():    dplyr, stats
lag():       dplyr, stats
matches():   dplyr, sos   #from .Rprofile; doesn't seem to clobber findFn function
src():       dplyr, Hmisc
summarize(): dplyr, Hmisc
> cty0 = ggplot2::map_data("county")

Attaching package: ‘maps’

The following object is masked from ‘package:purrr’:

    map
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • I had just done the opposite! `purrr::map` but this works equally well. Thanks! – Rafael May 26 '17 at 16:55
  • Any idea why `ggplot2::map_data` actually attaches `maps`? – Axeman May 26 '17 at 16:55
  • From the function help page: "Description Easily turn data from the maps package in to a data frame suitable for plotting with ggplot2." – IRTFM May 26 '17 at 16:56
  • 1
    I'd say it was a ggplot2 bug in `map_data` - it should say `fortify(maps::map(....` or otherwise explicitly import the map function from the maps package. – Spacedman May 26 '17 at 17:58
  • You're probably held in higher esteem by Hadley than am I, especially with regard to mapping functions, so can you file the bug report? – IRTFM May 26 '17 at 19:51
  • There's some bug in the maps package that requires it to be attached in order to actually retrieve map data – hadley May 27 '17 at 00:19
  • it boils down to `get("countyMapEnv")` which fails if maps package not attached. Will report. – Spacedman May 27 '17 at 13:10
  • 1
    The next version of the maps package (v3.2, on github but not yet submitted) should fix the requirement to attach the package. – Alex Deckmyn May 29 '17 at 14:02