View source: R/annotation_variable.r
annotation_variable | R Documentation |
Creates an annotation variable that can be passed as an argument to
create_codebook
.
annotation_variable(
name,
instruction,
codes = NULL,
relations = NULL,
only_edit = F,
only_imported = F,
multiple = F
)
name |
The name/label of the variable. The name/label of the question. Recommended to keep short. Cannot contain a "." |
instruction |
A brief (think 1 or 2 sentences) instruction to the coder. |
codes |
The codes that the coder can choose from. Can be a
character vector, named character vector or data.frame. An unnamed
character vector creates simple codes. A named character vector uses the
labels as colors, either as HEX or a name recognized by browsers (see
https://www.w3schools.com/colors/colors_names.asp). A data.frame must
have a code column, and can use certain special columns (see details). For
most control, codes can be a list of 'code' objects created with
|
relations |
If specified, this becomes a 'relation' type annotation.
relations can be created with |
only_edit |
If TRUE, coders can only edit imported annotations. You
can import annotations in |
only_imported |
If TRUE, codes can only use codes that were used at least once in a unit in the imported annotations. |
multiple |
If TRUE, coder can select multiple codes for a selected piece of text before closing the popup. Note that they can always select multiple codes by opening the popup multiple times. The setting exists for cases where multiple codes for a selection are common (e.g. topics in a paragraph). |
Using a data.frame for the codes argument gives more flexibility. This data.frame should have a "code" column, and can in addition have a "color" and "parent" column The color should be a color name, either as HEX or a name recognized by browsers (see https://www.w3schools.com/colors/colors_names.asp) The parent column is only relevant if you have many codes and use selection="dropdown". The dropdown menu will then show the codes with parent names, and parent names are included in the search string. A parent can be the name of another code, and parents can have parents, thus creating trees (just make sure not to create cycles). Use case would for example be an ontology with actor -> government -> president, and issue -> economy -> taxes.
A variable object, to be used within the
create_codebook
function
# simple variable with simple codes
codes <- c("Economy", "War", "Health")
annotation_variable("topic", "Assign topics to words", codes = codes)
# quick hand for setting colors
codes <- c(Economy = "blue", War = "red", Health = "green")
annotation_variable("topic", "Assign topics to words", codes = codes)
# get codes from a data.frame
codes_df <- data.frame(
code = c("negative", "neutral", "positive"),
color = c("red", "grey", "green")
)
annotation_variable("sentiment", "Assign sentiment to words", codes_df)
# codes data.frame with parents
codes_df <- data.frame(
parent = c("", "actor", "government", "", "media", "newspaper"),
code = c("actor", "government", "president", "media", "newspaper", "NYT")
)
codes_df
annotation_variable(
"actors",
"Label actors. Use the most specific label available",
codes_df
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.