Git Product home page Git Product logo

mapmixture's People

Contributors

akihirao avatar tom-jenkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mapmixture's Issues

Pacific Ocean map

Hi Tom,

Thanks for this awesome tool, it's gonna be super helpful for a lot of people!
I found an issue that I don't know how to solve. I'm using the shinyapp and trying to plot the admixture proportions for an Indo-Pacific marine species, with data from the Red Sea to French Polynesia. I've been trying different coordinate reference systems and using the xmin xmax but I can't find any combination that doesn't split the Pacific Ocean at the 180º longitude. This might be an issue for other studies that might be interested in getting a plot centered in the Pacific Ocean instead of having the sites at the two extremes of the whole world map, as the one I attached here.

Do you think that this is something that could be solved?
Many thanks again!

Cheers,
Carlos

Mapmixture_map (1)

Using black and white base map with relief

Dear Tom,

Thanks for developing this package, its really great!
I was trying out different settings and base maps you posted on the GitHub, but unfortunately, the one I would like to use is not among them. I wanted to plot the pie charts on a map showing relief, so I tried the option of using raster from Natural Earth (https://github.com/Tom-Jenkins/mapmixture?tab=readme-ov-file#use-a-raster-as-the-basemap). It worked when I used the color base map, like you did, but I want to have the map in black and white. I downloaded this one (https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/raster/GRAY_50M_SR_W.zip), but when I tried to use it, I got the following error message in R:

<error/rlang_error>
Error in `ggplot2::scale_fill_manual()`:
! Continuous values supplied to discrete scale.
ℹ Example values: NA, NA, NA, NA, and NA
---
Backtrace:
     ▆
  1. ├─base (local) `<fn>`(x)
  2. └─ggplot2:::print.ggplot(x)
  3.   ├─ggplot2::ggplot_build(x)
  4.   └─ggplot2:::ggplot_build.ggplot(x)
  5.     └─base::lapply(data, npscales$train_df)
  6.       └─ggplot2 (local) FUN(X[[i]], ...)
  7.         └─ggplot2 (local) train_df(..., self = self)
  8.           └─base::lapply(self$scales, function(scale) scale$train_df(df = df))
  9.             └─ggplot2 (local) FUN(X[[i]], ...)
 10.               └─scale$train_df(df = df)
 11.                 └─ggplot2 (local) train_df(..., self = self)
 12.                   └─self$train(df[[aesthetic]])
 13.                     └─ggplot2 (local) train(..., self = self)
Run rlang::last_trace(drop = FALSE) to see 2 hidden frames.

Is there a way of using the black and white option with relief as a base map?
Also, I have some locations that have overlapping pie charts, so were you maybe thinking of implementing something like what ggrepel does with text?

I am adding the script I was using - I used the example data you provided.

# Load packages
library(mapmixture)
library(terra)
library(readr)

#Import the basemap

#colour version from example dowloaded from here: https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/raster/NE1_50M_SR_W.zip
earth <- terra::rast("NE1_50M_SR_W/NE1_50M_SR_W.tif") 

#black and white version dowloaded from here: https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/raster/GRAY_50M_SR_W.zip
earth_bw <- terra::rast("GRAY_50M_SR_W/GRAY_50M_SR_W.tif") 

# Read in admixture file format 1
file <- system.file("extdata", "admixture1.csv", package = "mapmixture")
admixture1 <- read.csv(file)

# Read in coordinates file
file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)

# Run mapmixture - example in colour map - plots the map with pie charts
mapmixture(admixture1, coordinates, crs = 3035, basemap = earth)

# Run mapmixture - black and white map - gives an error
mapmixture(admixture1, coordinates, crs = 3035, basemap = earth_bw)

Thanks!

Add more coordinate reference systems to shiny app

Opening this enhancement for users to request coordinate reference systems (CRS) to add to the Map Options CRS selection box.

The exact function used to transform vector data is st_transform() from the sf package. EPSG codes that are eligible for this function can be added to Mapmixture after successful testing. The current rationale for not including all eligible CRS is because including 1000s of options slows down the rendering of the CRS selection box on the UI.

crs_screenshot

cluster ordering issues

I am using mapmixture on a data set with more than 9 clusters and find there are some issues with cluster ordering and colors. Below is a minimal example illustrating the issues.

# prepare admixture dataframe with site1 mainly  cluster1, site2 mainly cluster 2, and site 3 mainly cluster 3
admixture_df<-data.frame(Site=c("site1","site2","site3"),
                 Ind=c("ind1","ind2","ind3"),
                 Cluster1=c(0.9,0.05,0.05),
                 Cluster2=c(0.02,0.8,0.05),
                 Cluster3=c(0.02,0.05,0.7),
                 Cluster10=c(0.02,0.05,0.1),
                 Cluster11=c(0.04,0.05,0.1)
                 )
cluster_cols=c("orange","skyblue","green4","gold","darkblue")
structure_plot(admixture_df = admixture_df, type="structure", legend = "right", cluster_cols=cluster_cols)

However, the resulting structure plot shows something different, namely that site2 is mainly cluster 10 and site3 cluster 11. This is incorrect; see figure below:
structure_plot
When I plot the admixture percentages on a map, the cluster assignments are correct. However, the colors do not match the order in which they are defined (for example, I intended cluster2 to be skyblue but it is gold); see code and figure below:

coords_df<-data.frame(Site=c("site1","site2","site3"), Longitude=c(5,15,25), Latitude=c(10,20,30))
mapmixture(admixture_df = admixture_df, coords_df = coords_df, cluster_cols=cluster_cols, expand = T)

mapmixture
What I think happens is that the clusters are internally ordered based on their names in a strict (i.e., not natural) sense as can be seen in the legend of the mapmixture plot where clusters 10 and 11 come before 2 and 3. In the mapmixture plot, this means that colors are not applied in the expected order. I believe that same internal ordering happens in the structure plot but for some reason, the cluster names in the legend are in the original order causing the cluster assignments to be incorrect.

Thanks

Pie size issue

I am using your mapmixture package to plot genotype frequencies for a steelhead study in the Pacific Northwest. It is really helpful, thanks for developing it. I had used scatterpie in the past, but mapmixture is great. I am encountering one issue that I wanted to ask you about. Many of my sites have 2-3 different genotypes. Those pies all look good. I have a few sites that are fixed for one genotype. When plotted together with the other pies, they are visibly smaller. I tried changing the site genotype frequencies to .99 and .01 instead of 1 and 0. This makes the pie the same size, but then there is a black line in the pie (understandably).

Have you encountered this issue or do you have any suggestions for remedying it?
I am using file format 1.
admix.csv
Locations_for_github.csv

Coordinates file not read even if site codes identical to admixture file

Dear, I'm tring to use the online version but unfortunatly, every time I upload the Admixture File and the Coordinates File, even though the locality IDs are identical, I recived this messag: "Site IDs do not match. Ensure site IDs are present and match in both admixture and coordinates files." How can I fix this issue? Thanks a lot!

Remove map borders

Hi Tom!
I am trying to plot some pie-charts in a map using the mapmixture package, following the code you provided for map2 as example (below).
The code worked perfectly well, but I would like to remove country borders from the map (like the one attached); is there any flag to change the basemap that allows to do that?
map_noborders

thank you very much in advance!!

map2 example code:

library(mapmixture)
library(rnaturalearthhires)

Install rnaturalearthhires package using:
install.packages("rnaturalearthhires", repos = "https://ropensci.r-universe.dev", type = "source")

file <- system.file("extdata", "admixture1.csv", package = "mapmixture")
admixture1 <- read.csv(file)

file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)

map2 <- mapmixture(
admixture_df = admixture1,
coords_df = coordinates,
cluster_cols = c("#f1a340","#998ec3"),
cluster_names = c("Group A","Group B"),
crs = 3035,
basemap = rnaturalearthhires::countries10[, c("geometry")],
boundary = c(xmin=-15, xmax=16, ymin=40, ymax=62),
pie_size = 1,
pie_border = 0.3,
pie_border_col = "white",
pie_opacity = 1,
land_colour = "#d9d9d9",
sea_colour = "#deebf7",
expand = TRUE,
arrow = TRUE,
arrow_size = 1.5,
arrow_position = "bl",
scalebar = TRUE,
scalebar_size = 1.5,
scalebar_position = "tl",
plot_title = "Admixture Map",
plot_title_size = 12,
axis_title_size = 10,
axis_text_size = 8
)

overlapping pies

Dear Tom,
Thanks for this package; it's convenient to use for great plots.
I've successfully created a map with pie charts representing the STRUCTURE results of my data. However, the pie charts are overlapping due to the close proximity of my populations. Is there a way to plot these pie charts separately, with lines or arrows pointing to their exact coordinates using mapmixture?
Thanks in advance,
Cigdem

Exporting admixture maps to .png or .pdf

Hi Tom,

I had a follow up question for you. I have been trying different functions to export the plots to a .png. When I tried ggsave, the pies end up with the black lines delineating the percentages of admixture extending beyond the pies (see attached). Or trying to save it through Rstudio as a .png, the pies end up a bit fuzzy in larger format (see attached). I am wondering what function you use to save the plots as they look much crisper on your github.

Thanks,
Samantha

Adding a shape file to the base map

It would be great if it would be possible to add a shape file, e.g. delineation of a habitat, to the basemap. At this point, it will always overlay the pie charts, and so far I haven't found a way to map the pie charts on top.

"Invalid input" even with the sample data

I'm getting "Invalid input: admixture_df and coord_df should be a data.frame or tibble in the correct format. Run ?mapmixture to check valid input formats." message, even with the included examples

`map1 <- mapmixture(admixture1, coordinates, crs = 3035)
Error in value[[3L]](cond) :
  Invalid input: admixture_df and coord_df should be a data.frame or tibble in the correct format. Run ?mapmixture to check valid input formats.
In addition: Warning messages:
1: In stringr::str_to_lower(colnames(df)) :
  restarting interrupted promise evaluation
2: In stringr::str_to_lower(colnames(df)) :
  internal error -3 in R_decompress1

head(coordinates)
Site Lat Lon
1 Bergen 60.65 4.77
2 Cromer 52.94 1.31
3 Flodevigen 58.42 8.76
4 Helgoland 54.18 7.90
5 Ile de Re 46.13 -1.25
6 Isles of Scilly 49.92 -6.33
head(admixture1)
Site Ind Cluster1 Cluster2
1 Bergen Ber01 0.9999 1e-04
2 Bergen Ber02 0.9999 1e-04
3 Bergen Ber03 0.9999 1e-04
4 Bergen Ber04 0.9999 1e-04
5 Bergen Ber05 0.9999 1e-04
6 Bergen Ber06 0.9999 1e-04`

Error on plotting

map1 <- mapmixture(admixture1, coordinates, crs = 3035)
Error in st_as_sf.data.frame(x = data, coords = c(3, 2)) :
missing values in coordinates not allowed

site_order not working

Hi Tom,

Just checking if you can fix the site_order issue I experienced. I cannot rearrange populations in the structure plot. I will attach the script and the files for your reference.

**Please note that this function is working on another dataset in the same R markdown. The only difference between them is sampling location, and number of populations. 6 pops = working, this 8 pops = not working. I also noticed that the plot is showing individuals on populations in alphabetical order, which is the NULL command.

Load packages

library(mapmixture)
library(ggplot2)
library(gridExtra)

Read in admixture file format 1

file <- file.path("D:/OneDrive - Victoria University of Wellington - STAFF/Documents/Moana Project/Data/01_Pcanaliculus/03_structure/MAPMIXTURE/BOP/Pcanaliculus.451.77loc.k2.mapmixture.csv")
admixture1 <- read.csv(file)
head(admixture1)

Read in coordinates file

file <- file.path("D:/OneDrive - Victoria University of Wellington - STAFF/Documents/Moana Project/Data/01_Pcanaliculus/03_structure/MAPMIXTURE/BOP/coordinates.csv")
coordinates <- read.csv(file)

Run mapmixture

map4 <- mapmixture(admixture1, coordinates,
cluster_cols = c("#003f5c", "#ffa600"),
cluster_names = c("Ancestry 1","Ancestry 2"),
crs = 4326,
boundary = c(xmin=175.5, xmax=178.5, ymin=-38.1, ymax=-36.5),
pie_size = 0.3,
)+

Adjust theme options

theme(
legend.position = "top",
plot.margin = margin(l = 10, r = 10),
)+

Adjust the size of the legend keys

guides(fill = guide_legend(override.aes = list(size = 5, alpha = 1)))

Traditional structure barplot

structure_barplot <- structure_plot(admixture1,
type = "structure",
cluster_cols = c("#003f5c", "#ffa600"),
site_dividers = TRUE,
divider_width = 0.4,
site_order = c("CO", "EC","MF","MKRU", "MT" ,"OH","OP","TH"),
labels = "site",
flip_axis = FALSE,
site_ticks_size = -0.05,
site_labels_y = -0.35,
site_labels_size = 2.2
)+

Adjust theme options

theme(
axis.title.y = element_text(size = 8, hjust = 1),
axis.text.y = element_text(size = 5),
)

Arrange plots

grid.arrange(map4, structure_barplot, nrow = 2, heights = c(4,1))

coordinates.csv
Pcanaliculus.451.77loc.k2.mapmixture.csv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.