mapmixture icon indicating copy to clipboard operation
mapmixture copied to clipboard

Error while plotting: missing values in coordinates not allowed

Open CNLove-260 opened this issue 11 months ago • 6 comments

Thank you for the great new package. I seem to be having some issues while attempting to run the commands with my own data however.

mapmixture(admixture1, coordinates, crs = 3035)

Error in st_as_sf.data.frame(x = data, coords = c(3, 2)) : missing values in coordinates not allowed

I saw that there was a similar issue in another comment, with the issue stemming from a CRS error. However, I have not yet tried altering the base map, so am unsure where the issue might be stemming from?

My data look something like:

head(coordinates)

Site lat lon 1 ASD 72769 30524 2 ZXC 66911 33627 3 BNM 92405 31533

head(admixture)

Site Ind Cluster1 Cluster2 Cluster3 Cluster4 Cluster5 5 ASD 11 0.473244 1e-05 1e-05 0.000010 0.526726 6 ASD 17 0.514554 1e-05 1e-05 0.000010 0.485416 7 ASD 18 0.441918 1e-05 1e-05 0.028100 0.529962 8 ASD 19 0.477872 1e-05 1e-05 0.000010 0.522098 9 ASD 35 0.474079 1e-05 1e-05 0.000010 0.525891

Thanks!

CNLove-260 avatar Feb 25 '25 03:02 CNLove-260

Hi @SquRunner,

Looking at your coordinates file, I can see you’ve already transformed the latitude and longitude column into the 3035 CRS.

Can you try using standard lat and lon values and see if that work for you? Internally, mapmixture() does the transformations for you depending on the CRS argument.

Thanks, Tom

Tom-Jenkins avatar Feb 25 '25 07:02 Tom-Jenkins

Thank you! This worked in accepting the coordinates, and I am now able to plot against the standard basemap! However, when I try working my my own .tiff map file, I am still getting an error:

map1 <- mapmixture(admixture_data, coordinates, crs = 3035, basemap = earth_base)

Error: [crop] extents do not overlap

My map file is in 'Lambert Azimuthal Equal Area' and I wonder if this is due to a crs mismatch issue still?

Thanks so much for your help!

CNLove-260 avatar Feb 26 '25 00:02 CNLove-260

Hi @SquRunner,

Good news on the coordinates.

On the .tiff file I am not sure here. I’m assuming you imported the .tiff via terra and so it is a rast object. You could try making sure the rast object is in WGS84 CRS (4326) before running mapmixture and see if that works. Otherwise, I might need to look at this on my system to see what’s happening. If it still isn’t working, please send me your .tiff and your data, or a subset of your data, to my email below and I will investigate.

[email protected]

Tom-Jenkins avatar Feb 26 '25 08:02 Tom-Jenkins

Thank you! This worked in accepting the coordinates, and I am now able to plot against the standard basemap! However, when I try working my my own .tiff map file, I am still getting an error:

map1 <- mapmixture(admixture_data, coordinates, crs = 3035, basemap = earth_base)

Error: [crop] extents do not overlap

My map file is in 'Lambert Azimuthal Equal Area' and I wonder if this is due to a crs mismatch issue still?

Thanks so much for your help!

Hello, did you manage to get this working?

Tom-Jenkins avatar Mar 13 '25 08:03 Tom-Jenkins

So so sorry for the delay! I have not been able to fix the issue quite yet. And will send you the map now. Thank you so much!

CNLove-260 avatar May 15 '25 19:05 CNLove-260

So so sorry for the delay! I have not been able to fix the issue quite yet. And will send you the map now. Thank you so much!

The raster you sent is not a standard .tif file as it has points, legends, text and many other features. This is why is there is an error and will not work because ggspatial, the package working under the hood to plot rasters in mapmixture, does not know how to handle such files.

I recommend you obtain your data in a classic raster format, then re-try this with mapmixture. For an example, see the Natural Earth rasters: https://www.naturalearthdata.com/downloads. The projection does need to be in WGS 84 (EPSG: 4326) for this to work with the basemap argument.

Tom-Jenkins avatar May 20 '25 16:05 Tom-Jenkins