Skip to content

Using black and white base map with relief #19

Description

@BalantM

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions