Skip to content

Commit c1a2f57

Browse files
committed
add hide_languages argument; fix some documentation
1 parent 754e163 commit c1a2f57

7 files changed

Lines changed: 108 additions & 40 deletions

File tree

R/ec_languages.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#' \item{morning_greetings}{This variable contains values from the \href{https://lingconlab.ru/tald/005_morning_greetings.html}{"Morning Greetings" chapter} (Naccarato, Verhees 2021) from the Typological Atlas of the Languages of Daghestan. The languages of Daghestan can be classified into three groups according to whether they feature morning greetings including questions about the night’s rest (value `Did you wake up?`), based on the combination of concepts like “morning” and “good” (value `Good morning`), and both stratagies (value `Both`).}
1919
#' \item{consonant_inventory_size}{This variable contains consonant inventory sizes based on \href{https://lingconlab.ru/tald/phonology.html}{"Phonology" chapter} (Moroz 2021) from the Typological Atlas of the Languages of Daghestan.}
2020
#' }
21+
#'
22+
#' @references Moroz, George (2021). “On phonology of East Caucasian languages”. In: Typological Atlas of the Languages of Daghestan (TALD), v 2.0.0. Ed. by Michael Daniel, Konstantin Filatov, Timur Maisak, George Moroz, Timofey Mukhin, Chiara Naccarato and Samira Verhees. Moscow: Linguistic Convergence Laboratory, NRU HSE. DOI: 10.5281/zenodo.6807070. https://lingconlab.ru/tald.
23+
#' @references Naccarato, Chiara and Samira Verhees (2021). “Morning greetings”. In: Typological Atlas of the Languages of Daghestan (TALD), v 2.0.0. Ed. by Michael Daniel, Konstantin Filatov, Timur Maisak, George Moroz, Timofey Mukhin, Chiara Naccarato and Samira Verhees. Moscow: Linguistic Convergence Laboratory, NRU HSE. DOI: 10.5281/zenodo.6807070. https://lingconlab.ru/tald.
2124

2225
"ec_languages"
23-

R/ec_tile_map.R

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66
#' @param title_position Character vector of length 1, which specifies the title's position. Possible values are \code{left}, \code{center}, and \code{right}. Default value is \code{left}.
77
#' @param annotate_feature Logical variable that specifies, whether to add feature values on the tile. This especially make sense in case of numeric features. Default value is \code{FALSE}.
88
#' @param abbreviation Logical variable that specifies, whether use abbreviations for languages specified in the package. Default value is \code{TRUE}.
9+
#' @param hide_languages Character variable that specifies, which languages should be removed from the template.
910
#'
1011
#' @returns a `ggplot2` object
1112
#' @export
1213
#'
1314
#' @examples
1415
#' ec_tile_map()
16+
#'
1517
#' ec_tile_map(ec_languages,
1618
#' feature_column = "morning_greetings",
1719
#' title = "Morning greetings (Naccarato, Verhees 2021)")
1820
#'
21+
#' ec_tile_map(ec_languages,
22+
#' feature_column = "consonant_inventory_size",
23+
#' title = "Consonant inventory size (Moroz 2021)",
24+
#' annotate_feature = TRUE)
25+
#'
1926
#' @importFrom ggplot2 ggplot
2027
#' @importFrom ggplot2 aes
2128
#' @importFrom ggplot2 annotate
@@ -31,13 +38,14 @@
3138
#' @export
3239

3340
ec_tile_map <- function(data = NULL,
34-
feature_column = "feature",
35-
title = NULL,
36-
title_position = "left",
37-
annotate_feature = FALSE,
38-
abbreviation = TRUE) {
41+
feature_column = "feature",
42+
title = NULL,
43+
title_position = "left",
44+
annotate_feature = FALSE,
45+
abbreviation = TRUE,
46+
hide_languages = NULL) {
3947

40-
# arguments check ---------------------------------------------------------
48+
# arguments check ---------------------------------------------------------
4149

4250
stopifnot("The argument 'title' should be a character vector with one value" =
4351
length(title) <= 1,
@@ -54,9 +62,14 @@ ec_tile_map <- function(data = NULL,
5462
"The argument 'abbreviation' should be a logical vector with one value" =
5563
length(abbreviation) == 1,
5664
"The argument 'abbreviation' should be a logical vector with one value" =
57-
is.logical(abbreviation))
65+
is.logical(abbreviation),
66+
"The argument 'hide_languages' should be a character vector with languages, see 'ec_languages$language' for the possible values" =
67+
is.character(hide_languages) | is.null(hide_languages),
68+
"The argument 'hide_languages' should be a character vector with languages, see 'ec_languages$language' for the possible values" =
69+
is.null(hide_languages) |
70+
hide_languages %in% RCaucTile::ec_languages$language)
5871

59-
# redefine title_position -------------------------------------------------
72+
# redefine title_position -------------------------------------------------
6073

6174
if(title_position == "left") {
6275
title_position <- 0
@@ -66,15 +79,15 @@ ec_tile_map <- function(data = NULL,
6679
title_position <- 1
6780
}
6881

69-
# ec_template() assignment ------------------------------------------------
82+
# ec_template() assignment ------------------------------------------------
7083

7184
if(is.null(data)){
7285
ec_template(title = title,
7386
title_position = title_position,
7487
abbreviation = abbreviation)
7588
} else {
7689

77-
# arguments check ---------------------------------------------------------
90+
# arguments check ---------------------------------------------------------
7891

7992
stopifnot(
8093
"Data should be a dataframe" =
@@ -86,35 +99,39 @@ ec_tile_map <- function(data = NULL,
8699
"The argument 'feature_column' should be a character vector with one value" =
87100
length(feature_column) == 1)
88101

89-
# merge EC dataset with data provided by a user ---------------------------
102+
# merge EC dataset with data provided by a user ---------------------------
90103

91104
for_plot <- merge(RCaucTile::ec_languages, data, all.x = TRUE)
92105

93-
# create a column with the name feature if there is no one ----------------
106+
if(!is.null(hide_languages)){
107+
for_plot <- for_plot[!(for_plot$language %in% hide_languages), ]
108+
}
109+
110+
# create a column with the name feature if there is no one ----------------
94111

95112
names(for_plot)[names(for_plot) == feature_column] <- "feature"
96113

97-
# add an 'alpha' column for the cases when there are NAs in data ----------
114+
# add an 'alpha' column for the cases when there are NAs in data ----------
98115

99116
for_plot$alpha <- ifelse(is.na(for_plot$feature), 0.2, 1)
100117

101-
# change labels to abbreviations ------------------------------------------
118+
# change labels to abbreviations ------------------------------------------
102119

103120
if(isTRUE(abbreviation)){
104121
for_plot$language <- ifelse(is.na(for_plot$abbreviation),
105122
for_plot$language,
106123
for_plot$abbreviation)
107124
}
108125

109-
# add feature values to the language names --------------------------------
126+
# add feature values to the language names --------------------------------
110127

111128
if(isTRUE(annotate_feature)){
112129
for_plot$language <- ifelse(is.na(for_plot$feature),
113130
for_plot$language,
114131
paste0(for_plot$language, "\n", for_plot$feature))
115132
}
116133

117-
# ec_tile_numeric() or ec_tile_categorical() ------------------------------
134+
# ec_tile_numeric() or ec_tile_categorical() ------------------------------
118135

119136
if(is.numeric(for_plot$feature)){
120137
ec_tile_numeric(data = for_plot,
@@ -136,7 +153,7 @@ ec_template <- function(title,
136153
title_position,
137154
abbreviation){
138155

139-
# fake variables for R CMD check to be succeedded -------------------------
156+
# fake variables for R CMD check to be succeedded -------------------------
140157

141158
x <- NULL
142159
y <- NULL
@@ -146,28 +163,28 @@ ec_template <- function(title,
146163
language <- NULL
147164
text_color <- NULL
148165

149-
# load data ---------------------------------------------------------------
166+
# load data ---------------------------------------------------------------
150167

151168
for_plot <- RCaucTile::ec_languages
152169

153-
# add a 'text_color' column for the text colors ---------------------------
170+
# add a 'text_color' column for the text colors ---------------------------
154171

155172
for_plot$text_color <- define_annotation_color(for_plot$language_color)
156173

157-
# create a factor for correct coloring in ggplot --------------------------
174+
# create a factor for correct coloring in ggplot --------------------------
158175

159176
for_plot$language_color <- factor(for_plot$language_color,
160177
levels = for_plot$language_color)
161178

162-
# change labels to abbreviations ------------------------------------------
179+
# change labels to abbreviations ------------------------------------------
163180

164181
if(isTRUE(abbreviation)){
165182
for_plot$language <- ifelse(is.na(for_plot$abbreviation),
166183
for_plot$language,
167184
for_plot$abbreviation)
168185
}
169186

170-
# create a map ------------------------------------------------------------
187+
# create a map ------------------------------------------------------------
171188

172189
for_plot |>
173190
ggplot2::ggplot(ggplot2::aes(x, y)) +
@@ -186,24 +203,24 @@ ec_tile_numeric <- function(data,
186203
title_position,
187204
annotate_feature,
188205
abbreviation){
189-
# fake variables for R CMD check to be succeedded -------------------------
206+
# fake variables for R CMD check to be succeedded -------------------------
190207

191208
x <- NULL
192209
y <- NULL
193210
feature <- NULL
194211
alpha <- NULL
195212

196-
# load data ---------------------------------------------------------------
213+
# load data ---------------------------------------------------------------
197214

198215
for_plot <- data
199216

200-
# add a 'text_color' column for the text colors ---------------------------
217+
# add a 'text_color' column for the text colors ---------------------------
201218

202219
for_plot$text_color <- ifelse(is.na(for_plot$feature),
203220
"grey60",
204221
"grey90")
205222

206-
# create a map ------------------------------------------------------------
223+
# create a map ------------------------------------------------------------
207224

208225
for_plot |>
209226
ggplot2::ggplot(ggplot2::aes(x, y,
@@ -234,24 +251,24 @@ ec_tile_categorical <- function(data,
234251
annotate_feature,
235252
abbreviation){
236253

237-
# fake variables for R CMD check to be succeedded -------------------------
254+
# fake variables for R CMD check to be succeedded -------------------------
238255

239256
x <- NULL
240257
y <- NULL
241258
feature <- NULL
242259
alpha <- NULL
243260

244-
# load data ---------------------------------------------------------------
261+
# load data ---------------------------------------------------------------
245262

246263
for_plot <- data
247264

248-
# add a 'text_color' column for the text colors ---------------------------
265+
# add a 'text_color' column for the text colors ---------------------------
249266

250267
for_plot$text_color <- ifelse(is.na(for_plot$feature),
251268
"grey60",
252269
"#000000")
253270

254-
# create a map ------------------------------------------------------------
271+
# create a map ------------------------------------------------------------
255272

256273
for_plot |>
257274
ggplot2::ggplot(ggplot2::aes(x, y,

docs/index.html

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,17 @@ <h2 id="toc-title">Table of contents</h2>
8686
<li><a href="#introduction" id="toc-introduction" class="nav-link active" data-scroll-target="#introduction"><span class="header-section-number">1</span> Introduction</a></li>
8787
<li><a href="#installation" id="toc-installation" class="nav-link" data-scroll-target="#installation"><span class="header-section-number">2</span> Installation</a></li>
8888
<li><a href="#how-to-use-rcauctile" id="toc-how-to-use-rcauctile" class="nav-link" data-scroll-target="#how-to-use-rcauctile"><span class="header-section-number">3</span> How to use <code>RCaucTile</code></a></li>
89-
<li><a href="#changing-the-default-colors" id="toc-changing-the-default-colors" class="nav-link" data-scroll-target="#changing-the-default-colors"><span class="header-section-number">4</span> Changing the Default Colors</a></li>
90-
<li><a href="#changing-values-order" id="toc-changing-values-order" class="nav-link" data-scroll-target="#changing-values-order"><span class="header-section-number">5</span> Changing values order</a></li>
89+
<li><a href="#changing-the-default-colors" id="toc-changing-the-default-colors" class="nav-link" data-scroll-target="#changing-the-default-colors"><span class="header-section-number">4</span> Changing the default colors</a></li>
90+
<li><a href="#changing-values-order" id="toc-changing-values-order" class="nav-link" data-scroll-target="#changing-values-order"><span class="header-section-number">5</span> Changing values’ order</a></li>
91+
<li><a href="#changing-the-language-template" id="toc-changing-the-language-template" class="nav-link" data-scroll-target="#changing-the-language-template"><span class="header-section-number">6</span> Changing the language template</a></li>
9192
</ul>
9293
</nav>
9394
</div>
9495
<main class="content" id="quarto-document-content">
9596

9697
<header id="title-block-header" class="quarto-title-block default">
9798
<div class="quarto-title">
98-
<h1 class="title">RCaucTile: Tile Grid Maps for East Caucasian Languages</h1>
99+
<h1 class="title"><code>RCaucTile</code>: Tile Grid Maps for East Caucasian Languages</h1>
99100
</div>
100101

101102

@@ -280,7 +281,7 @@ <h2 data-number="3" class="anchored" data-anchor-id="how-to-use-rcauctile"><span
280281
</div>
281282
</section>
282283
<section id="changing-the-default-colors" class="level2" data-number="4">
283-
<h2 data-number="4" class="anchored" data-anchor-id="changing-the-default-colors"><span class="header-section-number">4</span> Changing the Default Colors</h2>
284+
<h2 data-number="4" class="anchored" data-anchor-id="changing-the-default-colors"><span class="header-section-number">4</span> Changing the default colors</h2>
284285
<p>It is possible that the default colors provided by <code>ggplot2</code> are not suitable for your plots. So <code>ggplot2</code> provides several tools for changing them. The function <code>scale_fill_distiller()</code> will help to change the colors of numeric variables to one of the predefined palettes (<code>Blues</code>, <code>BuGn</code>, <code>BuPu</code>, <code>GnBu</code>, <code>Greens</code>, <code>Grey</code>, <code>Oranges</code>, <code>OrRd</code>, <code>PuBu</code>, <code>PuBuGn</code>, <code>PuRd</code>, <code>Purples</code>, <code>RdPus</code>, <code>Reds</code>, <code>YlGn</code>, <code>YlGnBu</code>, <code>YlOrBr</code>, <code>YlOrRd</code>). There is a <code>direction</code> argument that makes it possible to reverse the order of the colors in the palette.</p>
285286
<div class="cell">
286287
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
@@ -378,7 +379,7 @@ <h2 data-number="4" class="anchored" data-anchor-id="changing-the-default-colors
378379
</div>
379380
</section>
380381
<section id="changing-values-order" class="level2" data-number="5">
381-
<h2 data-number="5" class="anchored" data-anchor-id="changing-values-order"><span class="header-section-number">5</span> Changing values order</h2>
382+
<h2 data-number="5" class="anchored" data-anchor-id="changing-values-order"><span class="header-section-number">5</span> Changing values order</h2>
382383
<p>The default order of values in R is alphabetical. To impose a different order, you can use the <code>factor()</code> function. This function doesn’t change the values themselves, but it instructs R to treat an input vector as ordered. This can be important for features with a natural order. For example, the following demonstrates how to override the default alphabetical order using <code>factor()</code>.</p>
383384
<div class="cell">
384385
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>df <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">language =</span> <span class="fu">c</span>(<span class="st">"Avar"</span>, <span class="st">"Chechen"</span>, <span class="st">"Mehweb"</span>),</span>
@@ -396,6 +397,25 @@ <h2 data-number="5" class="anchored" data-anchor-id="changing-values-order"><spa
396397
</div>
397398
</div>
398399
</section>
400+
<section id="changing-the-language-template" class="level2" data-number="6">
401+
<h2 data-number="6" class="anchored" data-anchor-id="changing-the-language-template"><span class="header-section-number">6</span> Changing the language template</h2>
402+
<p>The East Caucasian language family exhibits significant dialectal differentiation. A unified genealogical classification of all idioms spoken in Daghestan does not exist. The default language inventory in <code>RCaucTile</code> is based on the genealogical classification from the Typological Atlas of the Languages of Daghestan (see <a href="https://lingconlab.ru/tald/languages.html">the languages page</a>). Therefore, it is highly probable that some researchers may wish to modify the default inventory by removing or altering the names of existing units.</p>
403+
<p>To remove specific languages from the template, list the desired languages in the <code>remove_languages</code> argument.</p>
404+
<div class="cell">
405+
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ec_tile_map</span>(ec_languages,</span>
406+
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="at">feature_column =</span> <span class="st">"morning_greetings"</span>,</span>
407+
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Morning greetings (Naccarato, Verhees 2021)"</span>,</span>
408+
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> <span class="at">remove_languages =</span> <span class="fu">c</span>(<span class="st">"Gigatli"</span>, <span class="st">"Shari"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
409+
<div class="cell-output-display">
410+
<div>
411+
<figure class="figure">
412+
<p><img src="index_files/figure-html/unnamed-chunk-19-1.png" class="img-fluid figure-img" width="1152"></p>
413+
</figure>
414+
</div>
415+
</div>
416+
</div>
417+
<p>In order to change the names of existing languages in the template, you need …</p>
418+
</section>
399419

400420
</main>
401421
<!-- /main column -->

0 commit comments

Comments
 (0)