Skip to content

Commit

Permalink
- simpler start for HC article
Browse files Browse the repository at this point in the history
- css rules for figure captions
- documenting creation of hex logo
  • Loading branch information
jmclawson committed Oct 2, 2023
1 parent d7c525a commit 1e45805
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
51 changes: 51 additions & 0 deletions R/create_logo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
create_logo <- function(){
sticker_plot <-
federalist_mfw |>
rename_category("NA", "?") |>
stylo2gg(viz = "pca",
shapes = FALSE,
labeling = 1,
highlight = c(3, 4),
legend = FALSE,
black = 1) +
theme_void() +
theme_transparent() +
scale_color_manual(
values = c("orange", "slategray2",
"wheat3", "thistle3"))

library(hexSticker)

sticker(sticker_plot,
package="stylo2gg",
p_size=30, p_y = 1.3,
s_x=1.05, s_y=.9,
s_width=2.1, s_height=2.0,
p_color = "#000000", p_fontface = "bold",
white_around_sticker = FALSE,
h_fill="#fefefe", h_color="#f39c12",
filename="man/figures/stylo2gg.png")

library(magick)

image_read("man/figures/stylo2gg.png") |>
image_rotate(-30) |>
image_crop("597x518-39+42") |>
image_rotate(60) |>
image_crop("597x517-0-0") |>
image_rotate(-30) |>
image_crop("517x597+40-40") |>
image_fill(color = "transparent",
refcolor = "black",
fuzz = 65, point = "+1+1") |>
image_fill(color = "transparent",
refcolor = "black",
fuzz = 65, point = "+516+589") |>
image_write(path = "man/figures/stylo2gg.png")

if(file.exists("man/figures/logo.png")){
file.remove("man/figures/logo.png")
}
use_logo("man/figures/stylo2gg.png")
file.remove("man/figures/stylo2gg.png")
}
4 changes: 4 additions & 0 deletions pkgdown/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.caption {
color: gray;
font-style: italic;
}
11 changes: 3 additions & 8 deletions vignettes/articles/hierarchical-clustering.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ knitr::opts_chunk$set(
)
```

```{r setup, message=FALSE, warning=FALSE}
library(stylo2gg)
```

In addition to two-dimensional relationships with principal components, stylo can also show a dendrogram for cluster analysis, showing texts' relationships based on their distance to each other. The resulting dendrogram shows texts in branches splitting off from one another at points that correspond to distance. In the orientation shown below, when two texts or groups of texts seem to have greater stylistic similarity, their branches will join nearer to the right side of the chart---nearer to a distance of zero. As the texts show greater dissimilarity, their branches will connect closer to the left side of the chart.
In stylometry, cluster analysis makes it easy to understand similarities and differences among texts in a large corpus by grouping them based on their contents. The stylo package visualizes these groups with hierarchical tree diagrams, or dendrograms, drawing connections among texts. In these charts, texts get placed in branches splitting off from one another at points that correspond to difference or distance. In the orientation shown below, when two texts or groups of texts seem to have greater stylistic similarity, their branches will join nearer to the right side of the chart---nearer to a distance of zero. As the texts show greater dissimilarity, their branches will connect closer to the left side of the chart.

```{r eval=FALSE, include=FALSE}
# Only run this code chunk interactively, to create the needed files
Expand Down Expand Up @@ -59,12 +55,11 @@ federalist_mfw_hc <- readRDS("federalist_mfw_hc.rds")
readRDS("articles_CA_120_MFWs_Culled_75__Classic Delta_.rds")
```


Using this `federalist_mfw_hc` object, stylo2gg will create a similar cluster analysis:

```{r, fig.cap="To prepare dendrograms for display, stylo2gg uses <a href='https://cran.r-project.org/web/packages/dendextend/index.html'>dendextend</a>."}
```{r, message=FALSE, warning=FALSE, fig.cap="To prepare dendrograms for display, stylo2gg uses <a href='https://cran.r-project.org/web/packages/dendextend/index.html'>dendextend</a>."}
#| fig.height: 10.0
library(stylo2gg)
federalist_mfw_hc |>
stylo2gg()
```
Expand Down

0 comments on commit 1e45805

Please sign in to comment.