diff --git a/DESCRIPTION b/DESCRIPTION
index 632bed3..0ba9b0c 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -18,9 +18,8 @@ Suggests:
Depends:
R (>= 3.6.0),
Imports:
- httr,
- jsonlite,
ggplot2,
- scales
+ scales,
+ stringi
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
diff --git a/NAMESPACE b/NAMESPACE
index b849dcb..fc690e2 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,11 +1,11 @@
# Generated by roxygen2: do not edit by hand
export(generate_orbits)
+export(generate_random_planets)
export(plot_orbits)
export(randomize_planet_positions)
export(sol_planets)
export(theme_enhance_solar)
import(ggplot2)
-import(httr)
import(scales)
-importFrom(jsonlite,fromJSON)
+import(stringi)
diff --git a/R/aaa.R b/R/aaa.R
index 87bf8ba..ef67360 100644
--- a/R/aaa.R
+++ b/R/aaa.R
@@ -6,3 +6,42 @@
#' @docType data
#' @export
sol_planets <- c("Mercury", "Venus", "Earth", "Mars", "Jupyter", "Saturn", "Uranus", "Neptune", "Pluto")
+
+
+
+
+c("cen-tau-ri", "pro-xi-ma", "al-pha", "pro-xi-mus", "ter-ra",
+ "sa-turn", "ju-pi-ter", "mer-cu-ry", "ve-nus", "u-ra-nus", "mars",
+ "nep-tune", "plu-to", "ni-bi-ru", "tra-pist", "zeus", "aph-ro-dite",
+ "a-res", "heph-aes-tus", "ty-phoon", "da-scher", "en-dor", "ka-mi-no",
+ "qua-sar", "no-va", "om-ni-sen", "dune", "a-ra-kis", "gla-tius",
+ "co-do-mi-ni-um", "dor-sai", "o-si-mio", "he-li-os", "leo", "hein-lein",
+ "a-ca-mar", "ach-ra-dy", "a-di-ge-on", "a-las-tria", "al-drea",
+ "von-tria", "al-di-bran", "al-ge-ron", "ach-eon", "a-lon-dra",
+ "cyg-nus", "a-ri-done", "a-ri-da-ni", "lep-tus", "am-leth", "am-di-vian",
+ "om-ri-con", "ma-jo-ris", "mi-no-ris", "leo-nis", "an-do-ria",
+ "an-go-sia", "ar-ge-lius", "ar-gus", "per-cii", "pro-me-thi-us",
+ "the-os", "ar-ret", "ar-va-da", "au-re-lia", "ba-lon-si", "bar-son",
+ "ba-ri-di-on", "ben-zar", "ben-thos", "kup-sic", "bo-kara", "bo-la-rus",
+ "bo-ra-dis", "bos-lic", "bren-ta-lia", "bri-toid", "he-lia",
+ "cal-do-nia", "cal-dos", "cal-leb", "ca-li-os", "ca-mus", "ca-no-pius",
+ "car-da-sia", "cas-tal", "ca-tu-lia", "ce-ti", "cor-van", "co-ri-dan",
+ "cyg-nia", "cyg-net", "da-ka-ra", "da-lan", "da-nu-la", "oxi-lia",
+ "dav-los", "de-cos", "de-des-tris", "cen-tris", "cat-los", "der-bia",
+ "der-mi-nia", "de-ni-us", "nig-mus", "stag-ni-us", "spho-li-us",
+ "shpo-rio", "dre-on", "val-les", "al-pes", "al-pus", "xar-ria",
+ "cor-do-via", "met-ne-ria", "cos-ma-dov", "ju-ne-ria", "del-ta",
+ "o-rio-na", "ci-ca-da", "am-ne-li-um", "noe-li-um", "au-ra",
+ "au-ro-ra", "em-bo-ria", "phan-tax", "ob-lox", "ob-li-via", "za-thu-ra",
+ "ar-chea", "cen-tus", "ep-si-lon", "au-pho-ria", "au-ro-ria",
+ "ma-ri-dia", "po-tel-mia", "hy-pho-ria", "ti-tan", "la-vi-tan",
+ "no-mi-cron", "mag-nus", "kep-lar", "del-phi", "nim-bus", "am-phus",
+ "mor-phus", "lamb-dus", "dus-to-pia", "mo-pi-um", "mo-li-um",
+ "pho-ri-um", "pho-ri-oso", "oso-li-um", "xe-li-um", "so-li-sia",
+ "so-lus", "ap-po-lus", "pho-bos", "chro-nos", "as-tos", "seg-mos",
+ "co-los", "dei-mos", "cog-nus", "sig-mus", "co-ro-li-os", "pe-ri-li-os",
+ "sep-tus", "mes-mus", "op-tus", "ne-bu-lus", "hec-tus", "me-gus",
+ "gi-gus", "te-rus", "pe-tus", "lu-mus", "pri-mus", "op-ti-mus",
+ "ori-gus", "xe-lo-phus", "meg-lo-vus", "al-pha-ni-us", "es-la-var",
+ "cel-les-ti-us", "stel-le-ra-sus", "ra-le-os", "pa-go-ya", "pul-sar"
+) -> planet_fragments
diff --git a/R/generate-random-planets.R b/R/generate-random-planets.R
new file mode 100644
index 0000000..cc85233
--- /dev/null
+++ b/R/generate-random-planets.R
@@ -0,0 +1,117 @@
+#' Generate a vector of `n` believable planetary names using hidden Markov model.
+#'
+#' \if{html}{
+#' \out{
}\figure{README-rando-1.png}{options: style="width:750px;max-width:75\%;"}\out{
}
+#' }
+#' \if{latex}{
+#' \out{\begin{center}}\figure{README-rando-1.png}\out{\end{center}}
+#' }
+#'
+#' @param num_planets how many planets?
+#' @return character vector of planet names
+#' @references Riffed from [planet-name-generator](https://github.com/sayamqazi/planet-name-generator).
+#' @export
+#' @examples
+#' generate_random_planets(15)
+#'
+#' set.seed(42)
+#' rando_planets <- generate_random_planets(12)
+#'
+#' rando_orbits <- generate_orbits(rando_planets)
+#'
+#' set.seed(123) # this produced a decent placements
+#'
+#' placed_planets <- randomize_planet_positions(rando_orbits)
+#'
+#' plot_orbits(
+#' orbits = rando_orbits,
+#' planet_positions = placed_planets,
+#' label_planets = TRUE,
+#' label_family = hrbrthemes::font_es_bold
+#' ) +
+#' hrbrthemes::theme_ipsum_es(grid="") +
+#' coord_equal() +
+#' labs(
+#' title = "Rando System"
+#' ) +
+#' theme_enhance_solar()
+
+generate_random_planets <- function(num_planets = 20) {
+
+ planets <- planet_fragments
+
+ syllables <- stringi::stri_split_fixed(planets, "-", simplify = TRUE)
+
+ total_syllables <- length(syllables)
+
+ syllables <- unique(syllables)
+
+ div_index <- length(syllables) / total_syllables
+
+ size <- length(syllables) + 1
+
+ freq <- matrix(0, nrow = size, ncol = size)
+
+ for (p in planets) {
+ lex <- stringi::stri_split_fixed(p, "-", simplify = TRUE)
+ lex_indices <- match(lex, syllables) - 1
+
+ if (length(lex_indices) > 1) {
+ row_indices <- lex_indices[-length(lex_indices)]
+ col_indices <- lex_indices[-1]
+ freq[cbind(row_indices, col_indices)] <- freq[cbind(row_indices, col_indices)] + 1
+ }
+
+ last_syllable_index <- lex_indices[length(lex_indices)]
+ freq[last_syllable_index, size - 1] <- freq[last_syllable_index, size - 1] + 1
+ }
+
+ max_names <- num_planets
+ num_names <- 0
+ planet_name <- ""
+
+ c("prime", "",
+ "B", "",
+ "alpha", "",
+ 'proxima', "",
+ "IV", "",
+ "V", "",
+ "C", "",
+ "VI", "",
+ "VII", "",
+ "VIII", "",
+ "X", "",
+ "IX", "",
+ "D", "",
+ "", "") -> suffixes
+
+ generated_planet_names <- c()
+
+ while (num_names < max_names) {
+
+ length <- sample(2:3, 1)
+ initial <- sample(0:(size - 2), 1)
+
+ planet_name <- ""
+ while (length > 0) {
+ while (all(freq[initial + 1, ] != 1)) {
+ initial <- sample(0:(size - 2), 1)
+ }
+
+ planet_name <- paste0(planet_name, syllables[initial + 1])
+ initial <- which(freq[initial + 1, ] == 1)[1] - 1
+ length <- length - 1
+ }
+
+ suffix_index <- sample(1:length(suffixes), 1)
+ planet_name <- paste(planet_name, suffixes[suffix_index])
+ generated_planet_names <- append(generated_planet_names, planet_name)
+
+ num_names <- num_names + 1
+ }
+
+ stringi::stri_trans_totitle(
+ stringi::stri_trim_both(generated_planet_names)
+ )
+
+}
diff --git a/R/ggsolar-package.R b/R/ggsolar-package.R
index c5a4117..12cc025 100644
--- a/R/ggsolar-package.R
+++ b/R/ggsolar-package.R
@@ -13,6 +13,5 @@
#' @name ggsolar
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)
-#' @import httr ggplot2 scales
-#' @importFrom jsonlite fromJSON
+#' @import ggplot2 scales stringi
"_PACKAGE"
diff --git a/README.Rmd b/README.Rmd
index bf83a00..d3ab73e 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -45,7 +45,7 @@ packageVersion("ggsolar")
```{r sol, fig.width=6, fig.height=6, dev.args=list(bg="transparent")}
sol_orbits <- generate_orbits(sol_planets)
-set.seed(1323) # this produced a decent placements
+set.seed(1323) # this produced decent placements
placed_planets <- randomize_planet_positions(sol_orbits)
@@ -64,6 +64,32 @@ plot_orbits(
theme_enhance_solar()
```
+## Rando!
+
+```{r rando, fig.width=6, fig.height=6, dev.args=list(bg="transparent")}
+set.seed(42)
+(rando_planets <- generate_random_planets(12))
+
+rando_orbits <- generate_orbits(rando_planets)
+
+set.seed(123) # this produced decent placements
+
+placed_planets <- randomize_planet_positions(rando_orbits)
+
+plot_orbits(
+ orbits = rando_orbits,
+ planet_positions = placed_planets,
+ label_planets = TRUE,
+ label_family = hrbrthemes::font_es_bold
+) +
+ hrbrthemes::theme_ipsum_es(grid="") +
+ coord_equal() +
+ labs(
+ title = "Rando System"
+ ) +
+ theme_enhance_solar()
+```
+
## ggsolar Metrics
```{r cloc, echo=FALSE}
diff --git a/README.md b/README.md
index 1de9442..0b8e2d3 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,8 @@ package.
The following functions are implemented:
- `generate_orbits`: Generate concentric circular orbits for “n” planets
+- `generate_random_planets`: Generate a vector of n believable planetary
+ names using hidden Markov model.
- `plot_orbits`: Return a skeleton of a ggplot2 plot of solar system
plot
- `randomize_planet_positions`: Generate random planetary positions
@@ -34,6 +36,7 @@ The following functions are implemented:
## Installation
``` r
+remotes::install_github("hrbrmstr/ggsolar")
```
NOTE: To use the ‘remotes’ install options you will need to have the
@@ -55,7 +58,7 @@ packageVersion("ggsolar")
``` r
sol_orbits <- generate_orbits(sol_planets)
-set.seed(1323) # this produced a decent placements
+set.seed(1323) # this produced decent placements
placed_planets <- randomize_planet_positions(sol_orbits)
@@ -76,14 +79,44 @@ plot_orbits(
+## Rando!
+
+``` r
+set.seed(42)
+(rando_planets <- generate_random_planets(12))
+## [1] "Ososi" "Morlambtune" "Obli Vi" "Lantitan" "Tanthos" "Onhy" "Lesbomor C" "Radido"
+## [9] "Lesstel" "Altan Prime" "Lasdre" "Brenta"
+
+rando_orbits <- generate_orbits(rando_planets)
+
+set.seed(123) # this produced decent placements
+
+placed_planets <- randomize_planet_positions(rando_orbits)
+
+plot_orbits(
+ orbits = rando_orbits,
+ planet_positions = placed_planets,
+ label_planets = TRUE,
+ label_family = hrbrthemes::font_es_bold
+) +
+ hrbrthemes::theme_ipsum_es(grid="") +
+ coord_equal() +
+ labs(
+ title = "Rando System"
+ ) +
+ theme_enhance_solar()
+```
+
+
+
## ggsolar Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
|:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:|
-| R | 7 | 0.35 | 98 | 0.30 | 35 | 0.27 | 97 | 0.37 |
-| YAML | 2 | 0.10 | 38 | 0.12 | 10 | 0.08 | 2 | 0.01 |
-| Rmd | 1 | 0.05 | 25 | 0.08 | 20 | 0.15 | 31 | 0.12 |
-| SUM | 10 | 0.50 | 161 | 0.50 | 65 | 0.50 | 130 | 0.50 |
+| R | 8 | 0.36 | 191 | 0.35 | 61 | 0.31 | 141 | 0.40 |
+| Rmd | 1 | 0.05 | 42 | 0.08 | 26 | 0.13 | 34 | 0.10 |
+| YAML | 2 | 0.09 | 38 | 0.07 | 10 | 0.05 | 2 | 0.01 |
+| SUM | 11 | 0.50 | 271 | 0.50 | 97 | 0.50 | 177 | 0.50 |
clock Package Metrics for ggsolar
diff --git a/inst/planets.txt b/inst/planets.txt
new file mode 100755
index 0000000..6fec8ca
--- /dev/null
+++ b/inst/planets.txt
@@ -0,0 +1,189 @@
+cen-tau-ri
+pro-xi-ma
+al-pha
+pro-xi-mus
+ter-ra
+sa-turn
+ju-pi-ter
+mer-cu-ry
+ve-nus
+u-ra-nus
+mars
+nep-tune
+plu-to
+ni-bi-ru
+tra-pist
+zeus
+aph-ro-dite
+a-res
+heph-aes-tus
+ty-phoon
+da-scher
+en-dor
+ka-mi-no
+qua-sar
+no-va
+om-ni-sen
+dune
+a-ra-kis
+gla-tius
+co-do-mi-ni-um
+dor-sai
+o-si-mio
+he-li-os
+leo
+hein-lein
+a-ca-mar
+ach-ra-dy
+a-di-ge-on
+a-las-tria
+al-drea
+von-tria
+al-di-bran
+al-ge-ron
+ach-eon
+a-lon-dra
+cyg-nus
+a-ri-done
+a-ri-da-ni
+lep-tus
+am-leth
+am-di-vian
+om-ri-con
+ma-jo-ris
+mi-no-ris
+leo-nis
+an-do-ria
+an-go-sia
+ar-ge-lius
+ar-gus
+per-cii
+pro-me-thi-us
+the-os
+ar-ret
+ar-va-da
+au-re-lia
+ba-lon-si
+bar-son
+ba-ri-di-on
+ben-zar
+ben-thos
+kup-sic
+bo-kara
+bo-la-rus
+bo-ra-dis
+bos-lic
+bren-ta-lia
+bri-toid
+he-lia
+cal-do-nia
+cal-dos
+cal-leb
+ca-li-os
+ca-mus
+ca-no-pius
+car-da-sia
+cas-tal
+ca-tu-lia
+ce-ti
+cor-van
+co-ri-dan
+cyg-nia
+cyg-net
+da-ka-ra
+da-lan
+da-nu-la
+oxi-lia
+dav-los
+de-cos
+de-des-tris
+cen-tris
+cat-los
+der-bia
+der-mi-nia
+de-ni-us
+nig-mus
+stag-ni-us
+spho-li-us
+shpo-rio
+dre-on
+val-les
+al-pes
+al-pus
+xar-ria
+cor-do-via
+met-ne-ria
+cos-ma-dov
+ju-ne-ria
+del-ta
+o-rio-na
+ci-ca-da
+am-ne-li-um
+noe-li-um
+au-ra
+au-ro-ra
+em-bo-ria
+phan-tax
+ob-lox
+ob-li-via
+za-thu-ra
+ar-chea
+cen-tus
+ep-si-lon
+au-pho-ria
+au-ro-ria
+ma-ri-dia
+po-tel-mia
+hy-pho-ria
+ti-tan
+la-vi-tan
+no-mi-cron
+mag-nus
+kep-lar
+del-phi
+nim-bus
+am-phus
+mor-phus
+lamb-dus
+dus-to-pia
+mo-pi-um
+mo-li-um
+pho-ri-um
+pho-ri-oso
+oso-li-um
+xe-li-um
+so-li-sia
+so-lus
+ap-po-lus
+pho-bos
+chro-nos
+as-tos
+seg-mos
+co-los
+dei-mos
+cog-nus
+sig-mus
+co-ro-li-os
+pe-ri-li-os
+sep-tus
+mes-mus
+op-tus
+ne-bu-lus
+hec-tus
+me-gus
+gi-gus
+te-rus
+pe-tus
+lu-mus
+pri-mus
+op-ti-mus
+ori-gus
+xe-lo-phus
+meg-lo-vus
+al-pha-ni-us
+es-la-var
+cel-les-ti-us
+stel-le-ra-sus
+ra-le-os
+pa-go-ya
+pul-sar
\ No newline at end of file
diff --git a/man/figures/README-rando-1.png b/man/figures/README-rando-1.png
new file mode 100644
index 0000000..80a7d0a
Binary files /dev/null and b/man/figures/README-rando-1.png differ
diff --git a/man/generate_random_planets.Rd b/man/generate_random_planets.Rd
new file mode 100644
index 0000000..c39b317
--- /dev/null
+++ b/man/generate_random_planets.Rd
@@ -0,0 +1,50 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/generate-random-planets.R
+\name{generate_random_planets}
+\alias{generate_random_planets}
+\title{Generate a vector of \code{n} believable planetary names using hidden Markov model.}
+\usage{
+generate_random_planets(num_planets = 20)
+}
+\arguments{
+\item{num_planets}{how many planets?}
+}
+\value{
+character vector of planet names
+}
+\description{
+Riffed from \href{https://github.com/sayamqazi/planet-name-generator}{planet-name-generator}.
+}
+\details{
+\if{html}{
+ \out{}\figure{README-rando-1.png}{options: style="width:750px;max-width:75\%;"}\out{
}
+}
+\if{latex}{
+ \out{\begin{center}}\figure{README-rando-1.png}\out{\end{center}}
+}
+}
+\examples{
+generate_random_planets(15)
+
+set.seed(42)
+rando_planets <- generate_random_planets(12)
+
+rando_orbits <- generate_orbits(rando_planets)
+
+set.seed(123) # this produced a decent placements
+
+placed_planets <- randomize_planet_positions(rando_orbits)
+
+plot_orbits(
+ orbits = rando_orbits,
+ planet_positions = placed_planets,
+ label_planets = TRUE,
+ label_family = hrbrthemes::font_es_bold
+) +
+ hrbrthemes::theme_ipsum_es(grid="") +
+ coord_equal() +
+ labs(
+ title = "Rando System"
+ ) +
+ theme_enhance_solar()
+}