-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function for improved visualisation of two-term-queries, v. 1
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
inst/explorer/global/corpus_plot_functions/improve_visualisation_of_2_terms.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Better visualise searches with 2 search terms | ||
#' | ||
#' @param df | ||
#' @param number_of_search_terms | ||
#' | ||
#' @return data frame | ||
improve_visualisation_of_2_terms <- function(df, number_of_search_terms) { | ||
if (number_of_search_terms == 2) { | ||
fill_farge_chr <- as.character(df$Term_color) | ||
for (i in unique(df$cx_ID)) { | ||
# Are there search hits for any term here? | ||
all_fills <- fill_farge_chr[df$cx_ID == i] ## FORENKL/SPEED UP DENNE. TROR DET ER DUMT MED LOOP | ||
# Sjekker om det er 1 treff: | ||
if (sum(is.na(all_fills)) == 1) { | ||
# Hvilken df (half of tile dedicated to search term) er tom? | ||
tom_df <- which(is.na(all_fills)) | ||
ikke_tom_df <- if (tom_df == 1) | ||
2 | ||
else | ||
1 | ||
df$Term_color[df$cx_ID == i & | ||
df$df == tom_df] <- | ||
df$Term_color[df$cx_ID == i & | ||
df$df == ikke_tom_df] | ||
} | ||
} | ||
} | ||
return(df) | ||
} | ||
# Special feature when two search terms: | ||
# Fills up entire tile when only one | ||
# term is present in document/day. | ||
# If both terms present, each get half the tile | ||
## Identifying, when multi-term search, | ||
## which tiles are occupied by only one search term | ||
## and fill the whole tile | ||
## (i.e. prepare the df) | ||
## with the corresponding fill: |