--- title: "Getting Started with milestoneR" author: "Michael Friendly" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Getting Started with milestoneR} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5, warning = FALSE, message = FALSE ) # Load package for building vignette if (requireNamespace("devtools", quietly = TRUE)) { devtools::load_all() } else { library(milestoneR) } ``` ## Introduction The `milestoneR` package provides R access to the [Milestones Project](http://datavis.ca/milestones) database, a comprehensive collection of important events in the history of data visualization. This vignette demonstrates how to: - Access milestone data - Search and filter milestones - Display results in various formats - Explore relationships between milestones, authors, and references ## Loading the package ```{r load} library(milestoneR) ``` ## Accessing data The package provides accessor functions for all main database tables: ```{r data-access} # Get all milestones ms <- milestone() cat("Total milestones:", nrow(ms), "\n") # Get all authors aut <- authors() cat("Total authors:", nrow(aut), "\n") # Get all references refs <- reference() cat("Total references:", nrow(refs), "\n") # Get keywords, subjects, and aspects kw <- keyword() subj <- subject() asp <- aspect() cat("Keywords:", nrow(kw), "\n") cat("Subjects:", nrow(subj), "\n") cat("Aspects:", nrow(asp), "\n") ``` ## Exploring milestones Let's look at the structure of the milestone data: ```{r explore-milestones} # View column names names(ms) # Look at a few key fields ms |> subset(select = c(mid, date_from, tag, location)) |> head(10) ``` ### Date range coverage ```{r date-range} # Date range of milestones cat("Earliest milestone:", min(ms$date_from_numeric, na.rm = TRUE), "\n") cat("Most recent milestone:", max(ms$date_from_numeric, na.rm = TRUE), "\n") # Count by century ms$century <- (ms$date_from_numeric %/% 100) * 100 ms$century |> table() |> print() ``` ## Searching milestones The package provides three specialized search functions. ### Full-text search Search across milestone fields (description, tag, note): ```{r search-text} # Find milestones mentioning "statistical" stat_ids <- search_milestones("statistical") cat("Found", length(stat_ids), "milestones mentioning 'statistical'\n") # Show the first few head(stat_ids) # Use regex to find "chart" OR "graph" chart_ids <- search_milestones("chart|graph", fields = c("description", "tag")) cat("\nFound", length(chart_ids), "milestones with 'chart' or 'graph'\n") # Search only in tags for items marked as "1st" (first) first_ids <- search_milestones("^1st", fields = "tag") cat("\nFound", length(first_ids), "milestone tags starting with '1st'\n") ``` ### Search by keywords ```{r search-keywords} # Find milestones tagged with "contour" contour_ids <- search_keywords("contour") cat("Milestones with 'contour' keyword:", paste(contour_ids, collapse = ", "), "\n") # Search for statistical keywords stat_kw_ids <- search_keywords("statistic") cat("\nMilestones with statistical keywords:", length(stat_kw_ids), "\n") ``` ### Search by author ```{r search-authors} # Find William Playfair's milestones playfair_ids <- search_authors("Playfair") cat("William Playfair's milestones:", paste(playfair_ids, collapse = ", "), "\n") # Find all authors named John john_ids <- search_authors("John", name_fields = "givennames") cat("\nMilestones by authors named John:", length(john_ids), "\n") # Search only last names nightingale_ids <- search_authors("Nightingale", name_fields = "lname") cat("\nMilestones by Nightingale:", paste(nightingale_ids, collapse = ", "), "\n") ``` ## Filtering by date and category Combine direct data frame operations with search functions: ```{r filtering} # Milestones from the 1800s ms_1800s <- ms |> subset(date_from_numeric >= 1800 & date_from_numeric < 1900) cat("Milestones from 1800-1899:", nrow(ms_1800s), "\n") # Early milestones (before 1700) early <- ms |> subset(date_from_numeric < 1700) cat("Milestones before 1700:", nrow(early), "\n") # Milestones in France france <- ms |> subset(!is.na(location) & grepl("France", location, ignore.case = TRUE)) cat("Milestones in France:", nrow(france), "\n") ``` ### Filtering by subject and aspect Using the linking tables: ```{r filter-categories} # Get milestones by subject m2subj <- milestone2subject() # Milestones with "Physical" subject physical_mids <- m2subj |> subset(subject == "Physical") |> getElement("mid") cat("Milestones with 'Physical' subject:", length(physical_mids), "\n") # Get milestones by aspect m2asp <- milestone2aspect() # Milestones with "Cartography" aspect carto_mids <- m2asp |> subset(aspect == "Cartography") |> getElement("mid") cat("Milestones with 'Cartography' aspect:", length(carto_mids), "\n") # Combine: Cartography AND Physical combined <- intersect(physical_mids, carto_mids) cat("\nMilestones that are both Physical and Cartography:", length(combined), "\n") ``` ## Working with epochs Epochs provide a way to group milestones into meaningful time periods. The package defines default historical epochs based on the time periods described in Friendly et al. (2015). ### Default epochs ```{r epochs} # Get default epoch definitions epochs <- define_epochs() print(epochs) ``` The default epochs span from 1500 to 2000, covering key periods in the history of data visualization from early maps and diagrams through the development of high-dimensional visualization methods. ### Classifying milestones by epoch Attach epoch labels to milestones to analyze their distribution across historical periods: ```{r epoch-analysis} # Extend epochs to cover all milestones (including prehistoric ones) extended_epochs <- define_epochs(extend = "before") # Attach epoch labels to each milestone ms$epoch <- get_epoch(ms$date_from_numeric, extended_epochs) # Frequency table of milestones by epoch table(ms$epoch) # Or as a data frame epoch_counts <- as.data.frame(table(epoch = ms$epoch)) print(epoch_counts) ``` This shows how milestones are distributed across different historical periods, with the "Golden Age" (1850-1900) containing the most milestones in the database. You can also create custom epochs for specific analyses using `style = "custom"` with your own breaks and labels. See `?define_epochs` for more details. ## Displaying results The package provides several print functions with various output formats: `"text"`, `"html"`, `"markdown"`, `"cli"` (enhanced console output). ### Printing individual milestones ```{r print-milestone} # Print Halley's 1701 contour map in text format halley <- ms |> subset(date_from_numeric == 1701) print_milestone(halley$mid) ``` ### Different output formats ```{r print-formats, eval=FALSE} # HTML format (useful for R Markdown documents) print_milestone(53, result = "html") # Markdown format print_milestone(53, result = "md") # Enhanced CLI format with clickable links (in modern terminals) print_milestone_cli(53) ``` ### Printing multiple milestones ```{r print-multiple, eval=FALSE} # Print Playfair's milestones print_milestone_cli(playfair_ids) ``` ### Selective sections You can control which sections to display: ```{r print-selective, eval=FALSE} # Show only authors, media, and references print_milestone(53, include = c("authors", "media", "references")) ``` ### Search with formatted output Combine search with immediate formatted display: ```{r search-print} # Find and print Florence Nightingale's work search_milestones("Florence Nightingale", fields = "description", output = "print") ``` ## Working with related information Use helper functions to get related data for milestones. ### Getting authors ```{r get-authors} # Get authors for Halley's milestone halley_authors <- get_milestone_authors(53) halley_authors |> subset(select = c(givennames, lname, birthdate, deathdate)) |> print() # Get authors for multiple milestones playfair_authors <- get_milestone_authors(playfair_ids) playfair_authors |> subset(select = c(givennames, lname, birthdate)) |> print() ``` ### Getting references ```{r get-references} # Get references for a milestone halley_refs <- get_milestone_references(53) halley_refs |> subset(select = c(rid, author, year, title)) |> print() # Print formatted reference print_reference(halley_refs[1, ]) ``` ### Getting keywords ```{r get-keywords} # Get keywords for a milestone halley_kw <- get_milestone_keywords(53) print(halley_kw) # Get all keywords for Playfair's work playfair_kw <- get_milestone_keywords(playfair_ids) playfair_kw$keyword |> table() |> print() ``` ### Getting media items ```{r get-media} # Get media items for a milestone halley_media <- get_milestone_media(53) halley_media |> subset(select = c(miid, type, title)) |> print() # Check how many milestones have media all_media <- get_milestone_media(ms$mid) cat("Total media items:", nrow(all_media), "\n") cat("Milestones with media:", length(unique(all_media$mid)), "\n") ``` ## Printing references and authors ### References ```{r print-refs} # Print a reference in text format print_reference(halley_refs[1, ]) # Print as BibTeX cat("\nAs BibTeX:\n") print_reference(halley_refs[1, ], bibtex = TRUE) # Print multiple references print_reference(halley_refs) ``` ### Authors ```{r print-authors} # Print author information print_author(halley_authors[1, ]) # Get a specific author by name playfair_aut <- aut |> subset(grepl("Playfair", lname)) print_author(playfair_aut[1, ]) ``` ## Example workflow: Researching a topic Here's a complete example of researching "contour maps" in the history of data visualization: ```{r workflow} # 1. Search for contour-related milestones contour_text <- search_milestones("contour", fields = c("description", "tag")) contour_kw <- search_keywords("contour") # Combine results (union) contour_all <- unique(c(contour_text, contour_kw)) cat("Found", length(contour_all), "contour-related milestones\n") # 2. Get the milestone data contour_ms <- ms |> subset(mid %in% contour_all) # 3. Sort by date contour_ms <- contour_ms[order(contour_ms$date_from_numeric), ] # 4. Display summary cat("\nContour map milestones chronology:\n") for (i in 1:nrow(contour_ms)) { cat(sprintf("[%s] %s\n", contour_ms$date_from[i], contour_ms$tag[i])) } # 5. Get all authors involved contour_authors <- get_milestone_authors(contour_all) cat("\nAuthors involved in contour mapping:\n") unique_authors <- unique(contour_authors[, c("givennames", "lname", "birthdate")]) unique_authors[order(unique_authors$birthdate), ] |> print() # 6. Print detailed information for the earliest one cat("\n--- Earliest Contour Map Milestone ---\n") print_milestone(contour_ms$mid[1]) ``` ## Combining filters Create complex queries by combining multiple search strategies: ```{r complex-search} # Find statistical graphics in the 1800s stat_ids <- search_milestones("statistical") stat_1800s <- ms |> subset(mid %in% stat_ids) |> subset(date_from_numeric >= 1800 & date_from_numeric < 1900) cat("Statistical graphics milestones in the 1800s:", nrow(stat_1800s), "\n") # Show them stat_1800s |> subset(select = c(mid, date_from, tag)) |> head(5) |> print() ``` ## Summary statistics Get overview statistics about the database: ```{r summary-stats} # Count by subject m2subj <- milestone2subject() subj_counts <- table(m2subj$subject) cat("Milestones by Subject:\n") print(subj_counts) # Count by aspect m2asp <- milestone2aspect() asp_counts <- table(m2asp$aspect) cat("\nMilestones by Aspect:\n") print(asp_counts) # Most common keywords (top 10) m2kw <- milestone2keyword() kw_counts <- m2kw$keyword |> table() |> sort(decreasing = TRUE) cat("\nTop 10 Keywords:\n") print(head(kw_counts, 10)) # Milestones per century century_table <- table(ms$century) cat("\nMilestones per Century:\n") print(century_table) ``` ## Next steps This vignette has covered the basics of accessing, searching, and displaying milestones data. For more advanced usage: - See `vignette("visualizing-milestones")` for creating plots and visualizations - Use `?search_milestones` for advanced search options - Explore `?print_milestone_cli` for enhanced console output with clickable links - Check the [package website](https://github.com/friendly/milestoneR) for updates ## References Friendly, M., Sigal, M. & Harnanansingh, D. (2015). "The Milestones Project: A Database for the History of Data Visualization." In Kimball, M. & Kostelnick, C. (Eds.) *Visible Numbers: The History of Data Visualization*, Chapter 10. London, UK: Ashgate Press. [preprint](http://datavis.ca/papers/MilestonesProject.pdf)