Skip to content

Commit a296be3

Browse files
committed
Add auto vis fn details to readme
1 parent 8e0114c commit a296be3

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

README.Rmd

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,42 @@ The function supports multiple LLM providers:
9898
- **Google Gemini**: Models like `gemini-1.5-flash`
9999
- **Anthropic Claude**: Models like `claude-1`
100100

101+
#### Advanced Usage
102+
103+
For datasets without suitable numeric columns, you can preprocess the data to create counts or other aggregations:
104+
105+
```r
106+
# Create daily counts from raw data
107+
library(dplyr)
108+
109+
daily_counts <- lab_data %>%
110+
group_by(specimen_date) %>%
111+
summarise(case_counts = n())
112+
113+
# Create visualisation using the processed data
114+
llm_auto_viz(daily_counts,
115+
user_prompt = "Show the trend of cases over time")
116+
```
117+
118+
You can also request specific features in your visualization by describing them in the user prompt:
119+
120+
```r
121+
# Request specific visualization features
122+
llm_auto_viz(daily_counts,
123+
user_prompt = "Create a line chart with red line colour and include a 7-day rolling average")
124+
125+
# Request group-based visualization for categorical data
126+
organism_counts <- lab_data %>%
127+
group_by(specimen_date, organism_species_name) %>%
128+
summarise(count = n(), .groups = 'drop')
129+
130+
llm_auto_viz(organism_counts,
131+
user_prompt = "Show trends of different organisms over time with distinct colours for each organism")
132+
```
133+
101134
#### Environment Variable Setup
102135

103-
To use the `llm_interpret()` function, you need to set up the following environment variables:
136+
To use the `llm_interpret()` or `llm_auto_viz()` functions, you need to set up the following environment variables:
104137

105138
```r
106139
# In your .Renviron file or before calling the function:
@@ -118,6 +151,36 @@ LLM_API_KEY=your-api-key-here
118151
LLM_MODEL=gpt-4o
119152
```
120153

154+
### Automated Visualisation Generation
155+
156+
The package includes an experimental function `llm_auto_viz()` that uses Large Language Models (LLMs) to automatically generate appropriate visualisations based on dataset structure and optional user guidance. This feature inspired by agentic workflows to simplify exploratory data visualisation for epidemiologists.
157+
158+
```r
159+
# Basic usage - let the LLM choose the most appropriate visualisation
160+
viz <- llm_auto_viz(lab_data)
161+
162+
# Provide guidance on the type of visualisation needed
163+
viz <- llm_auto_viz(lab_data,
164+
user_prompt = "Create a line chart showing trends over time.")
165+
166+
# Get the generated R code without executing it (for reviewing or modifying)
167+
code <- llm_auto_viz(lab_data, execute = FALSE)
168+
```
169+
170+
#### Key Features
171+
172+
- **Privacy Protection**: Only metadata (column names, types, and summary statistics) is shared with the LLM, never the actual data, ensuring confidentiality of sensitive health information.
173+
- **User-guided Visualisation**: Combine the standard structurally-aware prompt with your specific visualisation needs through the `user_prompt` parameter.
174+
- **Code Generation**: Use `execute = FALSE` to retrieve the generated R code for review, learning or further customisation instead of the visualisation itself.
175+
- **Data-aware Selection**: The LLM selects appropriate chart types and column mappings based on the dataset structure, choosing suitable date columns for x-axes and numeric columns for measurements.
176+
- **Exploratory Analysis**: Ideal for rapid exploratory analysis, especially for epidemiologists with limited R programming experience.
177+
178+
> **Note**: As LLM outputs are non-deterministic, this feature is not suitable for reproducible analytical pipelines. However, it excels at exploratory data analysis by providing instant, contextually appropriate visualisations.
179+
180+
#### Supported LLM Providers
181+
182+
The function supports multiple LLM providers:
183+
121184
## Package data
122185

123186
epiviz includes an anonymised sample dataset from the SGSS laboratory database: `lab_data()`

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,32 @@ plot <- line_chart(
8383
plot_interpretation <- llm_interpret(plot)
8484
```
8585

86+
### Automated Visualisation Generation
87+
88+
The package includes an experimental function `llm_auto_viz()` that uses Large Language Models (LLMs) to automatically generate appropriate visualisations based on dataset structure and optional user guidance. This feature inspired by agentic workflows to simplify exploratory data visualisation for epidemiologists.
89+
90+
```r
91+
# Basic usage - let the LLM choose the most appropriate visualisation
92+
viz <- llm_auto_viz(lab_data)
93+
94+
# Provide guidance on the type of visualisation needed
95+
viz <- llm_auto_viz(lab_data,
96+
user_prompt = "Create a line chart showing trends over time.")
97+
98+
# Get the generated R code without executing it (for reviewing or modifying)
99+
code <- llm_auto_viz(lab_data, execute = FALSE)
100+
```
101+
102+
#### Key Features
103+
104+
- **Privacy Protection**: Only metadata (column names, types, and summary statistics) is shared with the LLM, never the actual data, ensuring confidentiality of sensitive health information.
105+
- **User-guided Visualisation**: Combine the standard structurally-aware prompt with your specific visualisation needs through the `user_prompt` parameter.
106+
- **Code Generation**: Use `execute = FALSE` to retrieve the generated R code for review, learning or further customisation instead of the visualisation itself.
107+
- **Data-aware Selection**: The LLM selects appropriate chart types and column mappings based on the dataset structure, choosing suitable date columns for x-axes and numeric columns for measurements.
108+
- **Exploratory Analysis**: Ideal for rapid exploratory analysis, especially for epidemiologists with limited R programming experience.
109+
110+
> **Note**: As LLM outputs are non-deterministic, this feature is not suitable for reproducible analytical pipelines. However, it excels at exploratory data analysis by providing instant, contextually appropriate visualisations.
111+
86112
#### Supported LLM Providers
87113

88114
The function supports multiple LLM providers:
@@ -93,7 +119,7 @@ The function supports multiple LLM providers:
93119

94120
#### Environment Variable Setup
95121

96-
To use the `llm_interpret()` function, you need to set up the following environment variables:
122+
To use the `llm_interpret()` or `llm_auto_viz()` functions, you need to set up the following environment variables:
97123

98124
```r
99125
# In your .Renviron file or before calling the function:

0 commit comments

Comments
 (0)