Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Error with Plotting Cartogram - 'This function does not give correct centroids and distances for longitude/latitude data.'

$
0
0

I'm trying to use the wrld_simple data from the maptools package to plot a Cartogram that involves some European countries based on their Population in 2005:

countries = c('Austria', 'Belgium', 'Bulgaria', 'Cyprus', 'Czech Republic', 'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Iceland', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Norway', 'Poland', 'Portugal', 'Slovenia', 'Spain', 'Sweden', 'United Kingdom')

Using the maptools package, I got the wrld_simpl data, and retrieved the data for those particular countries:

data(wrld_simpl)

mapsimple = wrld_simpl[wrld_simpl$NAME %in% countries]

plot(mapsimple)

So far so good, but when I plot it out:

cartogram= cartogram(mapping1, "POP2005", itermax = 7)

Please use cartogram_cont() instead of cartogram().

Error: Using an unprojected map. This function does not give correct centroids and distances for longitude/latitude data:
Use "st_transform()" to transform coordinates to another projection.

I try using cartogram_cont:

> cartogram= cartogram_cont(mapping1, "POP2005", itermax = 7)

Error: Using an unprojected map. This function does not give correct centroids and distances for longitude/latitude data:
Use "st_transform()" to transform coordinates to another projection.

I tried transforming it to sf and then doing the st_transform(), but to no avail:

sfno = st_as_sf(mapping1)

sfnoproj = st_transform(sfno, coords = c("lon", "lat"), crs = "+proj=longlat +datum=WGS84", agr = "constant")

cartogram= cartogram_cont(sfnoproj, "POP2005", itermax = 7)

Error: Using an unprojected map. This function does not give correct centroids and distances for longitude/latitude data:

Use "st_transform()" to transform coordinates to another projection.

I'm assuming I don't have the correct values for the projection right. How would I know to set it better? If I were to use other values besides 'POP2005', how do I go about it? What does the 'itermax' in cartogram mean (I don't quite understand the given definition)

Any help would be greatly appreciated as I'm quite new to this. Thank you!!!!


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>