# R Visuals

R visual creation and ggplot2 patterns for PBIR reports.

- Repository: https://github.com/data-goblin/power-bi-agentic-development (1079 stars)
- Category: Writing
- License: GPL-3.0
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add data-goblin/power-bi-agentic-development --skill r-visuals -g -a claude-code -y`
Codex: `npx skills add data-goblin/power-bi-agentic-development --skill r-visuals -g -a codex -y`
Cursor: `npx skills add data-goblin/power-bi-agentic-development --skill r-visuals -g -a cursor -y`
Gemini CLI: `npx skills add data-goblin/power-bi-agentic-development --skill r-visuals -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add data-goblin/power-bi-agentic-development`

## Description

R visual creation and ggplot2 patterns for PBIR reports. Automatically invoke when the user mentions "R visual", "ggplot2", "ggplot in Power BI", or asks to "create an R visual", "add an R chart", "write an R visual script", "inject an R script into Power BI".

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# R Visuals in Power BI (PBIR)

> **Use `pbir` for every report mutation.** Read PBIR metadata only for diagnosis. If `pbir` is
> unavailable or lacks an operation, stop and report the gap; never edit report JSON directly.

R visuals execute R scripts (primarily ggplot2) to render static PNG images on the Power BI canvas. **ggplot2 is the preferred library** -- its grammar of graphics approach produces clean, publication-quality statistical visualizations with less code. R is particularly strong for statistical visualizations.

## Visual Identity

- **visualType:** `scriptVisual`
- **Data role:** `Values` (columns and measures, multiple allowed)
- **Data variable:** `dataset` (data.frame, auto-injected)
- **Row limit:** 150,000 rows
- **Output:** Static PNG at 72 DPI -- no interactivity

## Workflow: Creating an R Visual

### Step 1: Add the Visual

```bash
pbir add visual scriptVisual "Report.Report/Page.Page" --name RevenueByDateR \
  --data "Values:Sales.Date" --data "Values:Sales.Revenue"
```

### Step 2: Write the Script

```r
library(ggplot2)

p <- ggplot(dataset, aes(x=Date, y=Sales)) +
  geom_col(fill="#5B8DBE") +
  theme_minimal(base_size=12) +
  theme(panel.grid.major.x=element_blank())

print(p)  # MANDATORY for ggplot2
```

Critical rules:
- `print(p)` is **mandatory** for ggplot2 objects -- they do not auto-display in Power BI
- `dataset` is auto-injected as a data.frame; do not create it
- Access columns by index (`dataset[,1]`) to avoid name escaping issues
- Use backticks for column names with spaces: `` dataset$`Order Lines` ``

### Step 2b: Review

Before presenting the script to the user, dispatch the `r-reviewer` agent to validate correctness and provide design feedback.

### Step 3: Inject the Script

```bash
pbir visuals r "Report.Report/Page.Page/RevenueByDateR.Visual" --script-file chart.r
```

The CLI handles PBIR string escaping.

### Step 4: Validate

The rest: https://github.com/data-goblin/power-bi-agentic-development/blob/HEAD/plugins/custom-visuals/skills/r-visuals/SKILL.md
