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:
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):
Is it possible to achieve such a combination of ggplot and mapping packages in a programmable way?