Your dataset object contains 252 multipolygons with quite complex boundaries.
Are you after a list of lat and long values of all the points defining the multipolygons, or are you after a single latitude and longitude per country? eg. a centroid or what not?
You may want to clarify this part, as the technique used will differ.
I would like to have list of lat and long values of all points to use in ggplot2 similar to map_data('world')
Also if you provide how to get a single latitude and longitude per country (would be perfect in case in the future).
Well... the technique of plotting maps using a list of lat and long values is somewhat dated, I wouldn't call it current best practice. But it does work.
What you need to do is convert from sf package format (the current best practice) to sp package format, and then call ggplot2::fortify() on the result.
old_style <- as(dataset, "Spatial") %>%
fortify()
ggplot(old_style, aes(x = long, y = lat, group = group)) +
geom_polygon()
Oki, then as("Spatial") and fortify is the way for you to go. Just keep in mind that the example you linked - as neat & inspiring as it is - dates from 2017 and the world has moved on since then.
Error:
! `fortify(<SpatialPolygonsDataFrame>, region = ...)` is defunct' was deprecated in ggplot2 3.4.4 and is now defunct.
ℹ Please migrate to sf.
So the solution could be either to downgrade your ggplot2 installation to something lower than 3.4.4 (current version is 3.5.1) or migrate to sf, as the error message not so gently prods you - which would be also my suggestion.
As for serializing a R object to disk consider base::saveRDS() and its base::readRDS() partner.
You really should consider moving to sf - it is the current best practice. There is a reason why the fortify method for sp was deprecated and is now defunct.
You might be able to recreate the object, but it will be somewhat of a software archeology exercise. Using geom_polygon as a mapping tool in a new piece of code is kind of anachronism; let it enjoy its well earned rest...
You will be much better served by geom_sf() with a polygon type sf data frame in data position - and the rest of the example ggplot code, like color scales and annotations and what not, can remain with only minor tweaking.
I am certain you will find the "new" style sf objects easier to manipulate than the old style sp ones; I remember how excited I was when it came out; it made difficult things seem easy and was a game changer in spatial data processing.