I can produce a map of Europe and the bubble plot that would layer on top of the map but I do not know how to merge these together successfully. Will someone please help me do this? :)
Here is the code I have used to create the two separate components:
library(cowplot)
library(googleway)
library(ggplot2)
library(ggrepel)
library(ggspatial)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library("ggplot2")
theme_set(theme_bw())
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
## Produces the map of Europe ##
ggplot(data = world) +
geom_sf() +
coord_sf(xlim = c(-15, 55), ylim = c(34, 71), expand = FALSE)
cities <- read.csv("cities1_R.csv")
df <- cities
df$Country <- as.factor(df$Country)
head(df[ , c("City", "Country", "Latitude", "Longitude", "No..of.Samples")], 28)
## Produces Bubbles plot ##
ggplot(df, aes(x = Longitude, y = Latitude)) +
geom_polygon(df, aes(x= Longitude, y= Latitude, group=group), fill="grey", alpha=0.3)
geom_point(aes(color = Country, size = No..of.Samples), alpha = 0.9) +
scale_color_manual(values = c("#FF3300", "#0066CC", "#FFFF00", "#CC0066", "#9933CC",
"#00FFFF", "#FF9900", "#000000", "#00CC00",
"#999999", "#FF6666", "#FF3399", "#669933",
"#000099", "#6666FF", "#003300", "#66FF33", "#660066", "#FF99CC",
"#333333", "#CC33FF", "#CC6699", "#663300", "#330033", "#666600", "#CCFF00", "#CC9900",
"#990033")) +
scale_size(breaks = c(0, 25, 50, 75, 100, 125, 150, 175), range = c(0.5, 12)) # Adjust
the range of points size
The size of the bubbles is dependent on the no. of samples in the cities data. This is the table: cities1_R.csv file showing the data in a table format
City | Country | Latitude | Longitude | No..of.Samples | |
---|---|---|---|---|---|
1 | AMSTERDAM | NETHERLANDS | 52.37403 | 4.88969 | 22 |
2 | BARI | ITALY | 41.11148 | 3.53390 | 196 |
3 | BUDAPEST | HUNGARY | 47.49801 | 19.03991 | |
4 | LONDON | UNITED KINGDOM | 51.50853 | -0.12574 | |
5 | BERLIN | GERMANY | 52.52437 | 13.41053 | |
6 | COPENHAGEN | DENMARK | 55.67594 | 12.56553 | |
7 | LISBOA | PORTUGAL | 38.71667 | -9.13333 | |
8 | WARSZAW | POLAND | 52.22977 | 21.01178 | |
9 | DUBLIN | IRELAND | 53.33306 | -6.24889 | |
10 | LJUBLJANA | SLOVENIA | 46.05108 | 14.50513 | |
11 | BRUXELLES | BELGIUM | 50.85045 | 4.34878 | |
12 | PARIS | FRANCE | 48.85341 | 2.34880 | |
13 | WIEN | AUSTRIA | 48.20849 | 16.37208 | |
14 | ASTURIAS | SPAIN | 43.36140 | -5.85930 | |
15 | ATHENS | GREECE | 37.98380 | 23.72750 | |
16 | STOCKHOLM | SWEDEN | 59.32930 | 18.06860 | |
17 | SOFIA | BULGARIA | 42.69770 | 23.32190 | |
18 | ZAGREB | CROATIA | 45.81500 | 15.98190 | |
19 | NICOSIA | CYPRUS | 35.18560 | 33.38230 | |
20 | PRAGUE | CZECH REPUBLIC | 50.07550 | 14.43780 | |
21 | TALLINN | ESTONIA | 59.43700 | 24.75360 | |
22 | HELSINKI | FINLAND | 60.16990 | 24.93840 | |
23 | RIGA | LATVIA | 56.94960 | 24.10520 | |
24 | VILNIUS | LITHUANIA | 54.68720 | 25.27970 | |
25 | LUXEMBOURG CITY | LUXEMBOURG | 49.81530 | 6.12960 | |
26 | VALLETTA | MALTA | 35.89890 | 14.51460 | |
27 | BUCHAREST | ROMANIA | 44.42680 | 26.10250 | |
28 | BRATISLAVA | SLOVAKIA | 48.14860 | 17.10770 |
This is the map of Europe I have produced: Map of Europe
This is the bubble plot I have produced: Bubble ggplot
If someone knows how to merge the two ggplots that would be amazing. I tried using the geom_polygon function but I couldn't get it to work. Thank you in advance!