Hi, I appreciate it if someone could help me to make a similar map using ggplot2 in R. Would you mind helping me, please?
thank you
Hi, I appreciate it if someone could help me to make a similar map using ggplot2 in R. Would you mind helping me, please?
thank you
It would be tricky to reproduce your image one to one - but this piece of code should give you a start.
library(sf) # spatial data manipulation
library(dplyr) # general data frame manipulation
library(ggplot2) # ...because ggplot :)
library(giscoR) # spatial data from Eurostat
# countries of the world as a sf data frame
countries <- giscoR::gisco_get_countries(resolution = "10")
# area of interest - bottom left & top right corner first, then a bounding box
aoi <- data.frame(lat = c(30, 75),
long = c(-15, 35)) %>%
st_as_sf(coords = c("long", "lat"), crs = 4326) %>%
st_bbox() %>%
st_as_sfc() %>%
st_segmentize(units::set_units(1, degree)) %>%
st_transform(3035) # European Albers - a conical projection is a must here
# cut countries to size
countries_in_view <- countries %>%
st_transform(3035) %>%
st_intersection(aoi)
# now the action!
ggplot() +
geom_sf(data = aoi, fill = "gray70") + # first the background
geom_sf(data = countries_in_view, fill = "white") + # now the foreground
theme_void() # no distractions please!
You will need to provide the code for the localities yourself, and I am unsure of how to approach the dotted areas (it is quite possible these were hand drawn on the finished map; but without any idea about the raw data this is just my speculation)
Dear Jlacko,
thank you so much for finding your important time for me and helping me I appreciate it. The code I was trying is here---
rm(list=ls(all=TRUE))
library(readxl)
library(ggplot2)
library(rgdal)
library(sp)
library(sf)
library(dplyr)
setwd("D:/Analysis/Continents/spatial_plot/")
file <-read.csv("sample_data.csv", header = T)
# Reading Europe shapefile
Europe <- readOGR(
dsn= path.expand("D:/Analysis/World_Countries"),
layer="TM_WORLD_BORDERS_SIMPL-0.3",
verbose=FALSE
)
ggplot() +
geom_polygon(data = Europe, aes(x = long, y = lat, group = group), fill="#f4f3f3", color = "Black", size = 0.02) +
geom_point(aes(x= Longitude, y = Latitude, colour = Mean_values, shape = Variable), data = MCA, alpha = 4)+ #, size = Country
scale_color_gradientn(name="Standard values", colours=c( "#66CC99","#F26120"))+ # change color scale
coord_equal(ratio=1) + # square plot to avoid the distortion
coord_map("lambert", xlim = c(-15, -170), ylim = c(10, 85))+
scale_shape_manual(values=c(19, 15))+ #, 17
scale_size_manual(values=c(3, 2))+ #, 4
guides(shape = guide_legend(override.aes = list(colour = c( "#66CC99","#F26120")))) + ## Change legend shape colors
theme(legend.position="bottom")+
labs(x="", y="", title="")+ #labels
facet_wrap(~ Century, ncol = 2)+
theme_bw()
Please, can you help me finding my mistakes (some times lat-long shrinks one side)
my data looks like this--
Century | Variable | Mean_values | Latitude | Longitude | Elevation (m) |
---|---|---|---|---|---|
800 | Temp | 1.077865651 | 62.55 | -153.633333 | 320 |
900 | Temp | -1.139270001 | 62.55 | -153.633333 | 320 |
1000 | Temp | 1.058128538 | 62.55 | -153.633333 | 320 |
1100 | Temp | 0.176537507 | 62.55 | -153.633333 | 320 |
1200 | Temp | -1.178744226 | 62.55 | -153.633333 | 320 |
1300 | Temp | 0.005482531 | 62.55 | -153.633333 | 320 |
800 | Temp | -0.954756515 | 72.6 | -38.5 | 3200 |
900 | Temp | 0.445790152 | 72.6 | -38.5 | 3200 |
1000 | Temp | -0.007414765 | 72.6 | -38.5 | 3200 |
1100 | Temp | 0.546643015 | 72.6 | -38.5 | 3200 |
1200 | Temp | -1.24718762 | 72.6 | -38.5 | 3200 |
1300 | Temp | -0.462729575 | 72.6 | -38.5 | 3200 |
800 | Precip | 0.199488452 | 72.6 | -38.5 | 3200 |
900 | Precip | 1.541942655 | 72.6 | -38.5 | 3200 |
1000 | Precip | 0.536791115 | 72.6 | -38.5 | 3200 |
1100 | Precip | -0.158603281 | 72.6 | -38.5 | 3200 |
1200 | Precip | -0.952745759 | 72.6 | -38.5 | 3200 |
1300 | Precip | -1.166873182 | 72.6 | -38.5 | 3200 |
800 | Precip | -1.398941525 | 38.704767 | -90.081279 | 122 |
900 | Precip | -0.534359638 | 38.704767 | -90.081279 | 122 |
1000 | Precip | -0.318214167 | 38.704767 | -90.081279 | 122 |
1100 | Precip | -0.030020204 | 38.704767 | -90.081279 | 122 |
1200 | Precip | 0.978658663 | 38.704767 | -90.081279 | 122 |
1300 | Precip | 1.302876871 | 38.704767 | -90.081279 | 122 |
I am sorry but I don't quite follow - what are you trying to achieve? The first point (the one with -153.63333 longitude) does not seem to be in Europe, but someplace like Alaska? This is definitely out of scope of the map you provided, which ends in like 15° west...
Dear Jlacko,
thank you very much for your response. I appreciate it.
You are right, that point is nearby Alaska. By the way, I have solved the issue. I got an Idea from your script and I converted data to the spatial form. Finally, got a similar map which I want to . Once again thank you for helping me
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.