1

I visualize some data using ggplot2 package with facets. Data can be, e.g., distribution of some values over different continents (or cities, countries etc). Here are some toy data and a standard solution for making a primary plot with facet_grid() function.

    library(ggplot2)  # key library
    library(reshape2) # to convert to long format 
     databas<-read.csv(data=
    "continent,apples,bananas
    North America,30,20
    South America,15,34.5
    Europe,15,19
    Africa,5,35")
    databaslong<-melt(databas) # default conversion, will make first col.as id 
    # plotting as colored bars
    ggplot(databaslong,aes(x=variable,y=value,fill=variable))+geom_col()+facet_grid(.~continent)

Following is predictably produced:

simple bar plot with facets

But now I would like to have more control on the positions of facets. Particularly, it seems natural to put each on the world map onto respective positions on continents, that is some action typical for tmap or similar packages. For example, use native ggplot instrumentality:

mapWorld <- borders("world", colour="gray50", fill="gray50")
ggplot() + mapWorld

and to get like such (manually combined these two layers in inkscape):

world map with facets

Is it possible to achieve such a combination of ggplot and mapping packages in a programmable way?

astrsk
  • 375
  • 6
  • 20
  • 1
    See this answer: https://stackoverflow.com/questions/45411140/small-ggplot2-plots-placed-on-coordinates-on-a-ggmap/45417727#45417727 – Brian Sep 18 '17 at 22:01
  • 1
    Check out the `geofacet` [package](https://github.com/hafen/geofacet) – dshkol Sep 19 '17 at 05:46

0 Answers0