Skip to content

Commit

Permalink
Change basemap data to comply with CRAN
Browse files Browse the repository at this point in the history
To comply with CRAN policy, the high resolution basemap originally distributed with mapmixture v1.1.1 has been replaced with the medium resolution basemap distributed with the `rnaturalearthdata` package, which `mapmixture` now imports as default for the `mapmixture()` function. See the `mapmixture` GitHub example page for the single line of code needed to import the high resolution basemap from the `rnaturalearthhires` package.
  • Loading branch information
Tom-Jenkins committed Apr 29, 2024
1 parent 40b6433 commit 251db7e
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 68 deletions.
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# mapmixture 1.1.1
## mapmixture 1.1.2

* Initial CRAN submission.
* To comply with CRAN policy, the high resolution basemap originally distributed with mapmixture v1.1.1 has been replaced with the medium resolution basemap distributed with the `rnaturalearthdata` package, which `mapmixture` now imports as default for the `mapmixture()` function. See the `mapmixture` GitHub example page for the single line of code needed to import the high resolution basemap from the `rnaturalearthhires` package.
* Added extra arguments to customise scatter plot site divider lines.
* Minor updates to documentation.

## mapmixture 1.1.1

* First release on CRAN.
34 changes: 18 additions & 16 deletions R/func_mapmixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#' mapmixture(
#' admixture_df = admixture1,
#' coords_df = coordinates,
#' cluster_cols = c("blue","green"),
#' cluster_cols = c("#f1a340","#998ec3"),
#' cluster_names = c("Group 1","Group 2"),
#' crs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +units=m",
#' boundary = c(xmin=-15, xmax=16, ymin=40, ymax=62),
Expand Down Expand Up @@ -103,19 +103,19 @@ mapmixture <- function(

# Download countries10.rda file to mapmixture extdata directory if not present
# https://github.com/ropensci/rnaturalearthhires
tryCatch({
filepath <- system.file("extdata", "countries10.rda", package = "mapmixture")
if (filepath == "") {
message("Downloading countries10 data from Natural Earth...")
url <- "https://github.com/ropensci/rnaturalearthhires/raw/master/data/countries10.rda"
desfile <- paste0(system.file("extdata", package = "mapmixture"), "/countries10.rda")
utils::download.file(url, destfile = desfile, mode = "wb")
message("Data downloaded to 'mapmixture/inst/extdata' folder.")
}
}, error = function(err) {
# Print error message if an error occurs from downloading
stop("Error downloading data from Natural Earth. Please check internet connection.")
})
# tryCatch({
# filepath <- system.file("extdata", "countries10.rda", package = "mapmixture")
# if (filepath == "") {
# message("Downloading countries10 data from Natural Earth...")
# url <- "https://github.com/ropensci/rnaturalearthhires/raw/master/data/countries10.rda"
# desfile <- paste0(system.file("extdata", package = "mapmixture"), "/countries10.rda")
# utils::download.file(url, destfile = desfile, mode = "wb")
# message("Data downloaded to 'mapmixture/inst/extdata' folder.")
# }
# }, error = function(err) {
# # Print error message if an error occurs from downloading
# stop("Error downloading data from Natural Earth. Please check internet connection.")
# })


# Standardise input data ----
Expand All @@ -140,10 +140,12 @@ mapmixture <- function(

# Read in world boundaries
# world_boundaries <- sf::st_read(system.file("extdata", "world.gpkg", package = "mapmixture"), quiet = TRUE)
load(system.file("extdata", "countries10.rda", package = "mapmixture"))
# load(system.file("extdata", "countries10.rda", package = "mapmixture"))
world_boundaries <- rnaturalearthdata::countries50[, c("geometry")]

# Transform world boundaries to CRS
world_boundaries <- sf::st_transform(get("countries10"), crs = crs)
# world_boundaries <- sf::st_transform(get("countries10"), crs = crs)
world_boundaries <- sf::st_transform(world_boundaries, crs = crs)

# Transform coordinates in admix_coords object to CRS
admix_coords <- transform_df_coords(admix_coords, crs = crs)
Expand Down
80 changes: 56 additions & 24 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->
[![R-CMD-check](https://github.com/Tom-Jenkins/mapmixture/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Tom-Jenkins/mapmixture/actions/workflows/R-CMD-check.yaml)
[![cran](https://www.r-pkg.org/badges/version/mapmixture)](https://CRAN.R-project.org/package=mapmixture)
[![download](https://cranlogs.r-pkg.org/badges/grand-total/mapmixture)](https://CRAN.R-project.org/package=mapmixture)
<!-- [![Codecov test coverage](https://codecov.io/gh/Tom-Jenkins/mapmixture/branch/main/graph/badge.svg)](https://app.codecov.io/gh/Tom-Jenkins/mapmixture?branch=main) -->
<!-- badges: end -->

Expand Down Expand Up @@ -80,16 +81,20 @@ map1
```


#### Customised usage of mapmixture
#### Customised usage of mapmixture with a high resolution map

<details markdown="1">
<summary>Code</summary>
```{r dpi=300}
# Load package
# Load packages
library(mapmixture)
library(rnaturalearthhires)
# Read in admixture file format 3
file <- system.file("extdata", "admixture3.csv", package = "mapmixture")
# Install rnaturalearthhires package using:
# install.packages("rnaturalearthhires", repos = "https://ropensci.r-universe.dev", type = "source")
# Read in admixture file format 1
file <- system.file("extdata", "admixture1.csv", package = "mapmixture")
admixture3 <- read.csv(file)
# Read in coordinates file
Expand All @@ -98,11 +103,12 @@ coordinates <- read.csv(file)
# Run mapmixture
map2 <- mapmixture(
admixture_df = admixture3,
admixture_df = admixture1,
coords_df = coordinates,
cluster_cols = c("green","blue"),
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,
Expand All @@ -128,6 +134,31 @@ map2 <- mapmixture(
map2
```

#### Admixture map with single coloured circles

<details markdown="1">
<summary>Code</summary>
```{r dpi=300}
# Load package
library(mapmixture)
# Read in admixture file format 3
file <- system.file("extdata", "admixture3.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
map3 <- mapmixture(admixture1, coordinates, crs = 3035)
# map3
```
</details>
```{r dpi=300, echo=FALSE}
map3
```


#### Add additional geoms or theme options to mapmixture ggplot object

Expand All @@ -147,7 +178,7 @@ file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)
# Run mapmixture
map3 <- mapmixture(
map4 <- mapmixture(
admixture_df = admixture1,
coords_df = coordinates,
cluster_cols = c("#f1a340","#998ec3"),
Expand Down Expand Up @@ -177,11 +208,11 @@ map3 <- mapmixture(
)+
# Adjust the size of the legend keys
guides(fill = guide_legend(override.aes = list(size = 5, alpha = 1)))
# map3
# map4
```
</details>
```{r dpi=300, echo=FALSE}
map3
map4
```


Expand All @@ -204,7 +235,7 @@ file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)
# Run mapmixture
map4 <- mapmixture(
map5 <- mapmixture(
admixture_df = admixture1,
coords_df = coordinates,
cluster_cols = c("#f1a340","#998ec3"),
Expand Down Expand Up @@ -245,11 +276,11 @@ structure_barplot <- structure_plot(
)
# Arrange plots
# grid.arrange(map4, structure_barplot, nrow = 2, heights = c(4,1))
# grid.arrange(map5, structure_barplot, nrow = 2, heights = c(4,1))
```
</details>
```{r dpi=300, echo=FALSE, }
grid.arrange(map4, structure_barplot, nrow = 2, heights = c(4,1))
grid.arrange(map5, structure_barplot, nrow = 2, heights = c(4,1))
```

<details markdown="1">
Expand All @@ -269,7 +300,7 @@ file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)
# Run mapmixture
map4 <- mapmixture(
map6 <- mapmixture(
admixture_df = admixture1,
coords_df = coordinates,
cluster_cols = c("#f1a340","#998ec3"),
Expand Down Expand Up @@ -300,11 +331,11 @@ facet_barplot <- structure_plot(admixture1,
)
# Arrange plots
# grid.arrange(map4, facet_barplot, ncol = 2, widths = c(3,2))
# grid.arrange(map6, facet_barplot, ncol = 2, widths = c(3,2))
```
</details>
```{r dpi=300, echo=FALSE, }
grid.arrange(map4, facet_barplot, ncol = 2, widths = c(3,2))
grid.arrange(map6, facet_barplot, ncol = 2, widths = c(3,2))
```


Expand All @@ -331,12 +362,12 @@ file <- system.file("extdata", "coordinates.csv", package = "mapmixture")
coordinates <- read.csv(file)
# Run mapmixture
map5 <- mapmixture(admixture1, coordinates, crs = 3035, basemap = earth)
# map5
map7 <- mapmixture(admixture1, coordinates, crs = 3035, basemap = earth)
# map7
```
</details>
```{r dpi=300, echo=FALSE}
map5
map7
```


Expand All @@ -349,6 +380,7 @@ The vector data (shapefile) used in the example below was downloaded from the Na
```{r dpi=300}
# Load packages
library(mapmixture)
library(rnaturalearthhires)
library(ggplot2)
library(dplyr)
library(sf)
Expand All @@ -366,8 +398,8 @@ crs <- 3035
boundary <- c(xmin=-11, xmax=13, ymin=50, ymax=60) |> transform_bbox(bbox = _, crs)
# Read in world countries from Natural Earth and transform to CRS
load(system.file("extdata", "countries10.rda", package = "mapmixture"))
world <- st_transform(get("countries10"), crs = crs)
world <- rnaturalearthhires::countries10[, c("geometry")]
world <- st_transform(world, crs = crs)
# Read in Marine Conservation Zones shapefile
# Extract polygons for Western Channel, Offshore Brighton and Swallow Sand
Expand All @@ -382,7 +414,7 @@ coords_df <- standardise_data(coordinates, type = "coordinates")
admix_coords <- merge_coords_data(coords_df, admixture_df) |> transform_df_coords(df = _, crs = crs)
# Plot map and add pie charts
map6 <- ggplot()+
map8 <- ggplot()+
geom_sf(data = world, colour = "black", fill = "#d9d9d9", size = 0.1)+
geom_sf(data = mczs, aes(fill = "MCZs"), linewidth = 0.3)+
scale_fill_manual(values = c("yellow"))+
Expand All @@ -402,11 +434,11 @@ map6 <- ggplot()+
theme(
legend.title = element_blank(),
)
# map6
# map8
```
</details>
```{r dpi=300, echo=FALSE}
map6
map8
```


Expand Down Expand Up @@ -545,7 +577,7 @@ library(mapmixture)
launch_mapmixture()
# Tested with the following package versions:
# shiny v1.8.0
# shiny v1.8.0 (important)
# shinyFeedback v0.4.0
# shinyjs v2.1.0
# shinyWidgets 0.8.4
Expand Down
Loading

0 comments on commit 251db7e

Please sign in to comment.