Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add plot argument #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: orthomap
Title: An R package to plot World in orthographic projection without aberrations
Version: 1.0.0
Date: 2017-12-06
Date: 2020-04-03
Authors@R: person("Nicolas", "Casajus", email = "[email protected]", role = c("aut", "cre"))
Description:
The package \textbf{orthomap} contains only one function: \code{orthomap()}. It corrects a bug (some polygons are not correctly projected) in the function \code{maps:map()} when it is used in orthographic projection. The function \code{orthomap()} also returns projected polygons in the \code{sp:SpatialPolygons} format.
Expand All @@ -14,5 +14,5 @@ LazyData: true
Imports: maps, mapproj, rgdal, rgeos, sp, stats
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
RoxygenNote: 6.0.1
RoxygenNote: 7.1.0
NeedsCompilation: no
75 changes: 40 additions & 35 deletions R/orthomap.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#'
#' @param query The name of a country to center the map on.
#' @param centre Latitude and longitude of the map center. Ignored if query is not \code{NULL}.
#' @param plot If TRUE, the map is plotted.
#' @param border.color Color of polygons border.
#' @param border.type Type of polygons border line (see argument \code{lty}).
#' @param border.size Size of polygons border line (see argument \code{lwd}).
Expand All @@ -32,6 +33,8 @@
#' @examples
#' # Default settings
#' world <- orthomap()
#' # Create the map but don't plot it
#' world <- orthomap(plot = FALSE)
#'
#' class(world)
#' length(world)
Expand Down Expand Up @@ -66,6 +69,7 @@
orthomap <- function(
query = NULL,
centre = c(0, 0),
plot = TRUE,
border.color = NA,
border.type = 1,
border.size = 0.25,
Expand Down Expand Up @@ -133,7 +137,7 @@ orthomap <- function(

### Find polygons delimitation

naloc <- (1L:nrow(coord))[!complete.cases(coord)]
naloc <- seq_len(nrow(coord))[!complete.cases(coord)]
naloc <- c(0, naloc, nrow(coord) + 1)


Expand Down Expand Up @@ -242,51 +246,52 @@ orthomap <- function(


### Plot world map in ortho
if (plot) {
graphics::par(...)

graphics::par(...)

ooo <- options()$warn
options(warn = -1)
maps::map("world", proj = "orthographic", orient = c(centre, 0), col = NA)
options(warn = ooo)

sp::plot(
globe,
col = globe.col,
border = grid.color,
lty = grid.type,
lwd = grid.size,
add = TRUE
)

sp::plot(
world,
col = fill,
border = border.color,
lty = border.type,
lwd = border.size,
add = TRUE
)

if (grid) {
ooo <- options()$warn
options(warn = -1)
maps::map("world", proj = "orthographic", orient = c(centre, 0), col = NA)
options(warn = ooo)

sp::plot(
globe,
col = "transparent",
col = globe.col,
border = grid.color,
lty = grid.type,
lwd = grid.size,
add = TRUE
)

mapproj::map.grid(
nx = nx,
ny = ny,
labels = FALSE,
col = grid.color,
lty = grid.type,
lwd = grid.size
sp::plot(
world,
col = fill,
border = border.color,
lty = border.type,
lwd = border.size,
add = TRUE
)

if (grid) {

sp::plot(
globe,
col = "transparent",
border = grid.color,
lty = grid.type,
lwd = grid.size,
add = TRUE
)

mapproj::map.grid(
nx = nx,
ny = ny,
labels = FALSE,
col = grid.color,
lty = grid.type,
lwd = grid.size
)
}
}

invisible(world)
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ Installation
To install the package **orthomap** from GitHub, first install the package [**devtools**](http://cran.r-project.org/web/packages/devtools/index.html) from the CRAN.

```r
### Install the < devtools > package
install.packages("devtools", dependencies = TRUE)

### Load the < devtools > package
library(devtools)
### Install the < emotes > package
install.packages("remotes")
```

Then install the **orthomap** package:

```r
### Install the < orthomap > package from GitHub
devtools::install_github("ahasverus/orthomap")
remotes::install_github("ahasverus/orthomap")

### Load the < orthomap > package
library(orthomap)
Expand Down
25 changes: 21 additions & 4 deletions man/orthomap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.