The Analysis of Characters in Dream of the Red Chamber

Cover image was generated by ChatGPT.
Introduction
Research Background and Process
Classical Chinese novels are an indispensable and important part of Chinese literature, with many masterpieces throughout history worthy of in-depth exploration. Among them, Dream of the Red Chamber is regarded as one of the representative works of classical Chinese fiction and possesses a high degree of scholarly interest. The fates of the characters and the numerous events in the novel are intricately and closely interconnected, requiring thorough study to fully understand their true significance.
In the process of investigation, we referred to the character relationship diagram Dream of the Red Chamber | Character Relationship Chart | Four Major Families | Blood Relations of Baoyu (寶玉), Daiyu (黛玉), Baochai (寶釵) | Understand the Characters of Dream of the Red Chamber in 5 Minutes | A Brief Discussion on Dream of the Red Chamber | 2023. The diagram shows that the relationships among characters are highly intricate. Even the four major families, despite being color-coded, are difficult to fully comprehend. However, this diagram was constructed by researchers after four days and nights of work, and they admit that completely understanding all character relationships remains challenging.
Although there exist novels with relatively simple character relationships, the profound research value of Dream of the Red Chamber has given rise to a new term in literary studies: “Redology.” In this study, Dream of the Red Chamber was chosen as the subject of analysis for specific reasons. First, it is a long vernacular novel, written in relatively easy-to-understand language. Compared to classical works that use a large amount of Classical Chinese, it is more suitable for text analysis and processing. Second, the novel features a fixed set of main characters, with the story progressing consistently from beginning to end through the same group of people. This continuity makes the relationships among characters clearer.
With the acceleration of modern life and the influx of abundant external information and stimuli, people’s attention spans are gradually decreasing. As a result, “summary guides” have emerged as a new popular trend, presenting information in a concise and easily understandable manner, while also being visually engaging. Such presentation aligns with the fast-paced lifestyle of contemporary society. This study aims to analyze the frequency and occurrence of characters in Dream of the Red Chamber and present the relationships and social circles of characters in a simple and intuitive way. This approach allows readers to better understand the main characters’ relationships. As a vernacular chaptered novel, Dream of the Red Chamber provides clear character relationships and accessible narrative, offering a valuable case for research and analysis. Beyond helping readers gain deeper insight into the novel’s character interactions, this study also seeks to meet modern demands for concise, comprehensible, and visually appealing information presentation.
Research Process
The research process and framework for this study are divided into the following five steps:
Research Process Explanation:
Confirm Outline
Based on exposure to various fields and applications, text mining techniques were chosen as the analytical tool. Existing research directions were explored through literature review to further define the research topic. Finally, the data was presented in a clear and intuitive manner.
Read Data
The text of Dream of the Red Chamber was converted into a format suitable for analysis using the R programming language. This included tasks such as tokenization, punctuation removal, extraction of characters and their aliases, and preliminary data processing.
| |
Perform Analysis
Visualization charts such as frequency bar charts, correlation matrices, and character relationship diagrams were created through data analysis. Preliminary analysis was performed on the data and charts to provide a basis for subsequent computational models.
Build Model
Using the
networkD3andRtsnepackages, an interactive network graph of character relationships was generated. This allows the research results to be shared online for comparison and reference.
Conclusions & Recommendations
Different models have different levels of interpretability. In this study, the results will be compared with initial predictions and then organized to form the conclusions. This process not only provides classification results but also yields important information such as character relationship maps, enabling further analysis and interpretation to extract more valuable insights.
Additionally, areas of the research process that could be further explored are documented along with suggested methodologies, providing inspiration for future researchers.
Literature Review
Overview of Analytical Methods
The following analytical methods were used in this study:
Correlation
The correlation coefficient is a numerical indicator used to describe the degree of relationship between two variables. Its value ranges from -1 to +1, where a positive correlation indicates a direct relationship, a negative correlation indicates an inverse relationship, and a value near zero indicates no relationship. Correlation coefficients help us understand the association between variables and identify trends in the data.
Wordcloud
A word cloud is a visualization method for textual data. It transforms large amounts of text into a visually interpretable graphic, where frequently occurring words are displayed in larger fonts at the center, and less frequent words appear in smaller fonts around the periphery. This provides a one-dimensional representation of the data.
MDS
MDS, or Multi-dimensional Scaling, is a technique that reduces high-dimensional data to two- or three-dimensional spaces for easier understanding and analysis. It is typically used to explore similarities or differences in data and display the data structure graphically. In the study of character relationships in Dream of the Red Chamber, MDS converts similarities between characters into distance units and maps these units into a two- or three-dimensional space, with each character represented as a point. The distances between points indicate the degree of similarity among characters.
Jaccard
The Jaccard index evaluates the similarity between two texts by dividing the number of shared words by the total number of unique words across both texts. In other words, the numerator represents the intersection, and the denominator represents the union. Using this function in R allows for precise calculation of similarity between texts, facilitating textual analysis and comparison.
PCA
Principal Component Analysis (PCA) reduces high-dimensional data to lower dimensions while retaining as much of the original variance as possible. It transforms a set of correlated variables into a new set of uncorrelated variables called principal components (PCs). Each PC is a linear combination of the original variables and is orthogonal to the others. The first PC captures the maximum variance in the data, and each subsequent PC captures the maximum remaining variance, provided it is orthogonal to the preceding PCs. The dimensionality reduction is achieved through linear combinations of the original variables ($x_1, x_2, x_3, …$).
t-SNE
t-SNE converts pairwise similarities into conditional probabilities, with similarities in the original space modeled by a Gaussian distribution and similarities in the embedded space modeled by a t-distribution. The main advantage of t-SNE is its ability to alleviate crowding issues after dimensionality reduction, allowing similar samples to cluster together while separating dissimilar samples, avoiding the dense and unclear point distributions common in other dimensionality reduction methods.
References from Papers and Related Research
To find suitable visualization methods, we referred to the thesis Interactive data visualization of text mining to Jin Yong Three Novels. The method used in this thesis was a word cloud: after extracting the necessary character names and merging their aliases, characters that appeared more frequently were displayed with larger fonts. This approach is visually striking, easy to understand, and meets the requirements for a “summary guide.” However, the word cloud is limited to showing the frequency of individual characters and cannot reveal one-to-one or one-to-many relationships between characters.
Next, we explored network graphs on the Zhihu website that could display character relationships. In these graphs, characters are represented as nodes, and the strength of relationships is indicated by the thickness of the connecting lines. Thicker lines represent stronger relationships, node size represents the frequency of character appearances, and color represents the family the character belongs to. Compared to word clouds, network graphs provide information about relationships between characters.
Even though network graphs address the issue of character-to-character relationships, they are still limited to showing single-character connections and cannot clearly depict many-to-many relationships. Therefore, we explored additional visualization methods to better analyze and present the data characteristics.
For this purpose, we extended from network graphs to clustering methods such as MDS, PCA, and t-SNE. However, the clustering results were still relatively dispersed. To improve this, we incorporated a filtering method called Jaccard on top of the original clustering techniques.
Research Methods
Packages Used
| Package | Description |
|---|---|
corrplot | Generates a correlation matrix to describe the relationships between different variables. |
tm | Facilitates text analysis, processing, and modeling in R, supporting the creation of word clouds, frequency charts, topic distribution plots, etc. |
wordcloud | Creates word cloud graphics with varying sizes and colors based on word frequency or weight. |
jiebaR | A Chinese text segmentation package for R, commonly used for tokenizing Chinese text. |
networkD3 | Creates interactive network graph visualizations. |
readxl | Used to read and parse Excel files. |
tidyverse | A collection of R packages including ggplot2, dplyr, tidyr, covering grouped statistics, data visualization, transformation, and more. |
igraph | Handles and transforms network graphs; used here to create edge data. |
magrittr | Makes chained function calls and data processing more readable and convenient, e.g., using %>%. |
dplyr | Provides fast, intuitive, and consistent data manipulation. |
ggpubr | An extension of ggplot2 that adds visualization and statistical analysis tools. |
MASS | Provides data analysis and modeling tools, including linear models and classification analysis. |
vegan | Used for ecological data analysis; in this study, it was applied for Jaccard-based adjustments. |
Rtsne | Reduces high-dimensional data to two or three dimensions for better understanding of data structure and relationships. |
Text Mining
Text mining involves extracting information of interest or uncovering useful knowledge from large amounts of text. By leveraging computational power, it filters and transforms vast textual content to identify hidden and valuable information. This process combines language processing, statistical analysis, and other methods to detect trends and relationships within the text.
Since Dream of the Red Chamber contains many vividly characterized individuals, R was used to organize the main characters and their aliases, determine their frequency of occurrence in the text, and facilitate subsequent analysis of interaction patterns between characters. This approach enhances the accuracy and reliability of further data analysis and model building.
| |
name_matrix concatenates the names of all characters appearing across all chapters. Its purpose is to facilitate text mining and streamline subsequent data processing.
| |
A blank matrix is initialized, and the custom text mining function stat_name is used to calculate the frequency of each character’s appearances in each chapter. The character names and their corresponding occurrence counts are then combined into the name matrix.
| |
The following code demonstrates the operation of the stat_name function. This approach was partially adapted and modified from Ming Chuan University thesis by 顏守玄 (2021) to fit the needs of this study.
| |
The name matrix, which contains occurrences for aliases of the same character, is merged into a single matrix representing the total appearances of each character across chapters. This facilitates subsequent statistical analyses.
| |
Through the above text mining and consolidation process, we obtain the total character appearance matrix. This matrix can be used for creating word clouds and conducting data analysis.

To extract relationships between characters, the name matrix is further simplified to indicate whether a character appears in a chapter. The result is stored in the person_exist matrix, referred to as the character presence matrix.
| |
Data Visualization
Data visualization presents information through graphical or chart-based formats, helping transform complex datasets into content that is easier to understand and interpret. In R, multiple packages support data visualization, including wordcloud and networkD3. The wordcloud package enables readers to quickly identify and focus on key themes across large volumes of text without needing to read the full content. In contrast, networkD3 uses visual elements such as color, node size, and link width to represent various data attributes, and it provides higher interactivity compared to traditional two-dimensional plots.

Research Discussion and Analysis
Data Cleaning
After loading the text into the compiler, we applied the previously developed filtering functions to extract the content of each chapter of Dream of the Red Chamber and compute the total number of appearances for each character. We then identified all relevant character names and constructed a matrix to record whether a character appears in each chapter. Using 1 and 0 to denote presence or absence, respectively, this matrix serves as the foundational dataset for all subsequent visualizations.
Next, using visualization packages in R, we generated a bar chart that ranks character appearances from most to least frequent, taking into account all aliases. Characters such as Baoyu (賈寶玉), Baochai (薛寶釵), Mother Jia (賈母), and Daiyu (林黛玉) appear prominently at the top, reflecting their central roles in the narrative.
This bar chart provides an intuitive means of understanding the relative importance and appearance frequency of each character in Dream of the Red Chamber.

Using the character occurrence matrix, we performed an initial visualization by applying corrplot to analyze correlations among all characters. The correlation strength is represented both numerically and through color gradients: darker colors indicate stronger correlations (absolute values closer to 1), while lighter colors indicate weaker correlations (values closer to 0).
For example, the correlation coefficient between Baoyu (賈寶玉) and Daiyu (林黛玉) is 0.38, suggesting a relatively strong relationship compared to other character pairs. In contrast, the coefficient between Granny Liu (劉姥姥) and Wang Xifeng (王熙鳳) is near zero, indicating little or no apparent connection.
This correlation matrix not only enables a straightforward comparison of relationships among characters but also serves as a reference for subsequent visualizations using network graphs, MDS, and PCA. By comparing results across these methods, we can better understand their respective strengths in representing and explaining the underlying data.
Word Cloud
We first generated the word cloud of total character appearances. This visualization is based on the word-cloud model presented in the referenced thesis (顏守玄, 2021), with modifications to better align with the objectives of this study. Using font size to represent keyword importance allows readers to instantly perceive the relative prominence or “heat” of each term.
Characters with higher appearance frequencies are rendered in larger font sizes, and characters with similar frequencies are shown in similar colors. However, while a word cloud effectively highlights the importance of keywords, it does not convey relationships between characters. In addition, when multiple keywords share the same visual size, differences in character length may lead to misinterpretation.

Network Graph
Because a word cloud cannot display character-to-character relationships, we adopted a network-graph approach inspired by the online article “Extracting Character Co-occurrence in Xue Zhong Han Dao Xing Using R and Visualizing with Network Graphs.” The article demonstrates how to generate highly interactive and intuitive network graphs, and its code structure serves as the foundation for our implementation.
To begin, we load the primary visualization package, networkD3, and apply the code framework introduced in the referenced article. In that workflow, the jiebaR package is used as the tokenizer. This package supports four segmentation modes and handles personal names, Simplified and Traditional Chinese, and keyword extraction.

In this type of network graph, node size represents the frequency of a character’s appearances. Edge thickness represents how often two characters appear together in the same chapter. Node colors indicate the family to which each character belongs.
However, when applying the original sample code to Dream of the Red Chamber, the results differed significantly from expectations and did not align with previously generated visualizations such as the bar chart of appearance frequencies, the correlation matrix, or the word cloud. For instance, the sample code incorrectly identified Mother Jia as the most frequently appearing character, whereas earlier analyses consistently show the top three as Baoyu (賈寶玉), Mother Jia (賈母), and Daiyu (林黛玉).
Through detailed inspection, we identified the root cause: the jiebaR tokenizer does not segment Dream of the Red Chamber reliably. While the novel leans toward vernacular Chinese, it retains enough classical phrasing that segmentation errors occur frequently. For example, occurrences of “黛玉” may be incorrectly parsed into forms such as “和黛玉,” “比黛玉,” or “黛玉同,” leading to inaccurate detection of character co-occurrence and, consequently, distorted network graphs.
To address this, we bypassed automated segmentation and instead leveraged the predefined character-appearance matrix constructed earlier. We defined co-occurrence strictly as the presence of two characters within the same chapter, assigning a value of 1 when the condition is satisfied and 0 otherwise. Based on this binary co-occurrence matrix, we recalculated connection frequencies and reconstructed the network graph:
After the adjustments, the network graph above reflects character relationships much more accurately. Compared with the results produced using R’s built-in tokenization tools, the revised graph presents relationships that are far more consistent with the data originally collected and more faithful to the narrative structure of Dream of the Red Chamber. Although related character pairs were merged and thicker edges were used to highlight stronger connections, the graph still contained a large number of edges, which created visual clutter and hindered readability.
To improve clarity, we removed all edges representing co-occurrence frequencies below 25. The resulting simplified network graph is shown below:
MDS
MDS, or Multi-dimensional Scaling, is a multivariate analysis technique and a form of dimensionality reduction. It maps high-dimensional data into a lower-dimensional space while preserving the relative distances between data points. The method computes Euclidean distances between all pairs of observations, then uses matrix operations to determine the spatial configuration of objects for visualization.
Below is the MDS plot illustrating the relative positions of characters. The visualization shows that the characters can be loosely grouped into three clusters, upper-left, upper-right, and lower-middle, yet the boundaries between groups remain relatively diffuse. To enhance the clarity of group separation, a similarity-based algorithm is introduced in the subsequent section.
Jaccard
The Jaccard index is a method for measuring the similarity between two objects. Its calculation is defined as the size of the intersection divided by the size of the union. When the Jaccard method is applied to the data used in the above MDS analysis, it reveals whether two characters appear together within the same chapter.
\begin{align*} J(A, B) = \frac{|A \cap B|}{|A \cup B|} \end{align*}
以下是添加了 Jaccard 後生成的 MDS 文字雲。從圖中可以清楚地看到群組中的點與點之間更加緊密,並且可以更好地觀察到人物之間的生活圈,以更好地判讀人物之間的關係。此外,藉由數據的相似度轉換,也可以有效將出場次數較少的人物分開,如 MDS 分群結果中妙玉看似和六到七位關係親密,但透過 Jaccard 轉換後,該人物即明顯與原先其他人物有一定距離,而小說故事狀況也是如此。 Below is the MDS word cloud generated after incorporating the Jaccard index. From the figure, it is evident that the points within each group are more closely clustered, allowing for clearer observation of characters’ social circles and facilitating the interpretation of their relationships. In addition, by transforming similarity based on data overlap, characters with fewer appearances can be effectively separated. For example, in the original MDS clustering results, Miaoyu (妙玉) appeared to be closely associated with six or seven characters, but after the Jaccard transformation, she is clearly positioned farther from them, reflecting the actual narrative structure of the novel.

PCA
After applying the Jaccard transformation to the data and plotting the results using PCA, we found that the output is similar to that of MDS, with a mirrored spatial arrangement. Based on the relative distances in the plot, the characters can be broadly grouped into three clusters: one consisting of Mother Jia (賈母) and Jia Baoyu (賈寶玉), another including Jia Yuanchun (賈元春) and Jia Yingchun (賈迎春), and a third cluster on the right side comprising six characters such as Jia Qiaojie (賈巧姐) and Miaoyu (妙玉). It is worth noting, however, that some uncertainties in clustering remain. The characters on the right side are still relatively dispersed, making it difficult to determine whether strong relationships exist among them. Therefore, we proceeded to employ t-SNE as an alternative dimensionality reduction method to assess whether it could provide clearer character clustering.
t-SNE
Using t-SNE for dimensionality reduction, and setting the perplexity value to 5, we found that it produced more distinct clusters compared to the previous two methods. The characters can be clearly divided into three major groups, suggesting that our dataset may be more suitable for nonlinear dimensionality reduction techniques, which yield better interpretability for this analysis. It is important to note that t-SNE produces different point distributions each time it is executed, resulting in non-deterministic outputs. Hence, multiple runs are required to obtain a satisfactory result. The following two figures present clustering outcomes that meet our expectations:
Conclusion and Recommendations
When deciding to conduct text mining on Dream of the Red Chamber, we considered that the novel is written in vernacular Chinese and features complex and closely intertwined character relationships. Therefore, we regarded it as an ideal text for mining and analysis.
Since the analyzed data are binary and asymmetric, we applied the Jaccard method to measure the similarity between key terms more accurately. In this study, we employed both linear dimensionality reduction methods (such as MDS and PCA) and nonlinear methods (such as t-SNE) to map high-dimensional data into two-dimensional space, making the visualizations easier to interpret while preserving as much information as possible. The results show that t-SNE is the most effective method among the three for distinguishing different character groups based on occurrence data.
The methods used in this study can also be applied to online media and text mining fields. Similar to the recent prominence of ChatGPT, they aim to extract valuable information from textual data. Additionally, for the literary field, this study provides a relatively objective tool for automatically analyzing text and extracting important information, such as character names and function words. Even without prior knowledge or deep understanding of the text, the results allow readers to grasp the relationships among key terms. Regardless of the reader’s familiarity with the content, this study offers a valuable resource akin to a “summary guide.”
During the research, we also created a dataset of total character occurrences, i.e., the total number of appearances of each character in each chapter of Dream of the Red Chamber. Future research can refer to our analytical approach, compare differences with the original model, and explore other dimensionality reduction methods to find more reasonable explanatory models. Additionally, during data collection, we found studies on the frequency of plant appearances, suggesting the potential for correlation analysis on other topics to explore relationships among variables. The visualized results also exhibit preliminary “summary guide” effects; compared to raw data, graphical presentations offer a more intuitive way for audiences to understand the information. In the future, we hope to implement interactive visualizations of data results using the Shiny package or other suitable tools, allowing users to interact with the data directly, enhancing accessibility and better serving the audience.
See Also
References
- 曹雪芹, 高鶚 (circa early Qianlong period). Dream of the Red Chamber (edited by 程偉元). Wikisource. https://zh.wikisource.org/zh-hant/紅樓夢
- 顏守玄 (2021). Interactive data visualization of text mining to Jin Yong Three Novels. Taiwan Thesis and Dissertation Knowledge Value-Added System. https://hdl.handle.net/11296/9a2p75
- 喵喵 (2020). Dream of the Red Chamber | Character Relationship Chart | Four Major Families | Blood Relations of Baoyu (寶玉), Daiyu (黛玉), Baochai (寶釵) | Understand the Characters of Dream of the Red Chamber in 5 Minutes | A Brief Discussion on Dream of the Red Chamber | 2023. NightelfMeowMeow. https://nightelfmeowmeow.com/378/1105014-reading-cn-novel-dream-of-the-red-chamber-family-tree/
- 重明論 (2021). Extracting Character Relationships from “Sword of Snow” Using R Co-occurrence and Plotting a Network Graph. Zhihu. https://zhuanlan.zhihu.com/p/388637831
- Lipkus, A. H. (1999, October). A proof of the triangle inequality for the Tanimoto distance. Journal of Mathematical Chemistry, 26(1–3), 263–265. https://link.springer.com/article/10.1023/A:1019154432472
- Flodel (2012). How to create an edge list from a matrix in R? Stack Overflow. https://stackoverflow.com/questions/13204046/how-to-create-an-edge-list-from-a-matrix-in-r
- Finnstats (2021, November). How to calculate Jaccard similarity in R. R-Bloggers. https://www.r-bloggers.com/2021/11/how-to-calculate-jaccard-similarity-in-r/
- Levandowsky, M., & Winter, D. (1971). Distance between sets. Nature, 234(5), 34–35. https://www.nature.com/articles/234034a0
- Kosub, S. (2016, December). A note on the triangle inequality for the Jaccard distance. https://arxiv.org/pdf/1612.02696.pdf
- Plotting PCA (Principal Component Analysis). https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_pca.html
- R: The R Project for Statistical Computing. https://www.r-project.org/
- RStudio. Posit. https://www.rstudio.com
- TSNE test. https://www.bioinformatics.babraham.ac.uk/tsne/
- Wordlayout: Word Layout. In wordcloud: Word Clouds. (2019). Rdrr.io. https://rdrr.io/rforge/wordcloud/man/wordlayout.html










![[Thought] Historical Earthquake Locations Around Taiwan](https://Josh-test-lab.github.io/posts/Historical%20Earthquake%20Locations%20Around%20Taiwan/cover%20image.webp)






