Example RADAR Report

Code
# Notebook setup

# Use quarto render to generate a static site in /docs
# Set github pages to deploy from main branch, /docs

# Insure packages are installed by checking required packages against installed packages
reqd_pkgs <- c("flextable",
               "sf",
               "tidyverse",
               "mapgl",
               "htmltools",
               "officer",
               "forcats",
               "socratadata",
               "mapgl",
               "mapview",
               "DBI",
               "RPostgres")

install.packages(
  setdiff(
    reqd_pkgs,
    rownames(installed.packages())
  ),
  repos = "https://cloud.r-project.org"
)

lapply(reqd_pkgs, library, character.only = TRUE) |> 
  invisible()

# If needed, ensure that the Quarto render and RStudio read the same environment vars
readRenviron(".Renviron")

### UNCOMMENT FOR POSTGIS VIA DOCKER ###########################################

# # Start Postgres via Docker, wait for healthcheck
# system("docker compose up -d --wait")
# 
# # Set up connection from env
# con <- dbConnect(RPostgres::Postgres())
# 
# # Enable PostGIS
# invisible(dbExecute(con, "CREATE EXTENSION IF NOT EXISTS postgis"))

###############################################################################
# Get cil_table()
source("cil_table.R")

This branch is for a brief RADAR report example that includes examples of typical elements:

The code block above contains per-block rendering options, denoted by #|. Look, code formatting! Required packages are then written to a character vector reqd_pkgs which is used to compare against already-installed R packages using the setdiff() function.

Once packages are installed, they may be used by calling the library() function. The common packages used here are:

Let’s set up some elements using the built-in datasets that come with R and the above packages.

To render the report as docs/index.html, run quarto render index.qmd from the command line in the repo root.

One of the packages in tidyverse is the popular ggplot2, used to create data analysis graphics using the “Grammar of Graphics”. A useful reference is the online book ggplot2: Elegant Graphics for Data Analysis (3e), which was made with Quarto!

The number of diamonds by color and cut in the built in diamonds data set can be visualized using a stacked bar chart. We’ll define the category color manually:

ggplot(data = diamonds,
       aes(color, fill = cut)) +
  geom_bar() + 
  xlab("Color Category") +
  ylab("Count") +
  labs(title = "Diamonds by Color and Cut",
       subtitle = "Source: diamonds (built-in dataset)") +
  scale_fill_discrete(name = "Color Category",
                      palette = c("#f1eef6",
                                  "#bdc9e1",
                                  "#74a9cf",
                                  "#2b8cbe",
                                  "#045a8d")) +
  theme_gray(base_size = 16)

Virtually every element of a ggplot graphic can be modified. Let’s say we want to remove the panel shading, leaving only y-axis major grid lines in a light grey, and update the text color to a softer black:

ggplot(data = diamonds,
       aes(color, fill = cut)) +
  geom_bar() + 
  xlab("Color Category") +
  ylab("Count") +
  labs(title = "Diamonds by Color and Cut",
       subtitle = "Source: diamonds (built-in dataset)") +
  scale_fill_discrete(name = "Color Category",
                      palette = c("#f1eef6",
                                  "#bdc9e1",
                                  "#74a9cf",
                                  "#2b8cbe",
                                  "#045a8d")) +
  scale_y_continuous( breaks = seq(0, 30000, by = 5000)) +
  theme_gray(base_size = 16) +
  theme(
    panel.background = element_blank(),
    panel.grid.major.y = element_line(color = "grey80"),
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank(),
    axis.ticks = element_blank(),
    text = element_text(color = "#141414"),
    axis.text = element_text(color = "#141414")
  )

And so and and so on. LLMs are good with helping with the arcane little tweaks for plots.

The sf package has a built in dataset of SIDS sample data in North Carolina. Let’s use mapgl to take a look at area by county:

nc <- st_read(system.file("shape/nc.shp", package="sf"),
              quiet = TRUE)

maplibre_view(nc, column = "AREA")


How about a table of the same information? Flextable is a little tricky in that its output is rendered as an HTML widget that generates its own HTML that gets injected into the page. To control the vertical height and overflow using styles.css you have to wrap the class using the html_tools package:

nc |>
  st_drop_geometry() |>
  cil_table()

AREA

PERIMETER

CNTY_

CNTY_ID

NAME

FIPS

FIPSNO

CRESS_ID

BIR74

SID74

NWBIR74

BIR79

SID79

NWBIR79

0.114

1.442

1,825

1,825

Ashe

37009

37,009

5

1,091

1

10

1,364

0

19

0.061

1.231

1,827

1,827

Alleghany

37005

37,005

3

487

0

10

542

3

12

0.143

1.630

1,828

1,828

Surry

37171

37,171

86

3,188

5

208

3,616

6

260

0.070

2.968

1,831

1,831

Currituck

37053

37,053

27

508

1

123

830

2

145

0.153

2.206

1,832

1,832

Northampton

37131

37,131

66

1,421

9

1,066

1,606

3

1,197

0.097

1.670

1,833

1,833

Hertford

37091

37,091

46

1,452

7

954

1,838

5

1,237

0.062

1.547

1,834

1,834

Camden

37029

37,029

15

286

0

115

350

2

139

0.091

1.284

1,835

1,835

Gates

37073

37,073

37

420

0

254

594

2

371

0.118

1.421

1,836

1,836

Warren

37185

37,185

93

968

4

748

1,190

2

844

0.124

1.428

1,837

1,837

Stokes

37169

37,169

85

1,612

1

160

2,038

5

176

0.114

1.352

1,838

1,838

Caswell

37033

37,033

17

1,035

2

550

1,253

2

597

0.153

1.616

1,839

1,839

Rockingham

37157

37,157

79

4,449

16

1,243

5,386

5

1,369

0.143

1.663

1,840

1,840

Granville

37077

37,077

39

1,671

4

930

2,074

4

1,058

0.109

1.325

1,841

1,841

Person

37145

37,145

73

1,556

4

613

1,790

4

650

0.072

1.085

1,842

1,842

Vance

37181

37,181

91

2,180

4

1,179

2,753

6

1,492

0.190

2.204

1,846

1,846

Halifax

37083

37,083

42

3,608

18

2,365

4,463

17

2,980

0.053

1.171

1,848

1,848

Pasquotank

37139

37,139

70

1,638

3

622

2,275

4

933

0.199

1.984

1,874

1,874

Wilkes

37193

37,193

97

3,146

4

200

3,725

7

222

0.081

1.288

1,880

1,880

Watauga

37189

37,189

95

1,323

1

17

1,775

1

33

0.063

1.000

1,881

1,881

Perquimans

37143

37,143

72

484

1

230

676

0

310

0.044

1.158

1,887

1,887

Chowan

37041

37,041

21

751

1

368

899

1

491

0.064

1.213

1,892

1,892

Avery

37011

37,011

6

781

0

4

977

0

5

0.086

1.267

1,893

1,893

Yadkin

37197

37,197

99

1,269

1

65

1,568

1

76

0.128

1.554

1,897

1,897

Franklin

37069

37,069

35

1,399

2

736

1,863

0

950

0.108

1.483

1,900

1,900

Forsyth

37067

37,067

34

11,858

10

3,919

15,704

18

5,031

0.170

1.680

1,903

1,903

Guilford

37081

37,081

41

16,184

23

5,483

20,543

38

7,089

0.111

1.392

1,904

1,904

Alamance

37001

37,001

1

4,672

13

1,243

5,767

11

1,397

0.180

2.151

1,905

1,905

Bertie

37015

37,015

8

1,324

6

921

1,616

5

1,161

0.104

1.294

1,907

1,907

Orange

37135

37,135

68

3,164

4

776

4,478

6

1,086

0.077

1.271

1,908

1,908

Durham

37063

37,063

32

7,970

16

3,732

10,432

22

4,948

0.142

1.640

1,913

1,913

Nash

37127

37,127

64

4,021

8

1,851

5,189

7

2,274

0.059

1.319

1,927

1,927

Mitchell

37121

37,121

61

671

0

1

919

2

4

0.131

1.521

1,928

1,928

Edgecombe

37065

37,065

33

3,657

10

2,186

4,359

9

2,696

0.122

1.516

1,932

1,932

Caldwell

37027

37,027

14

3,609

6

309

4,249

9

360

0.080

1.307

1,936

1,936

Yancey

37199

37,199

100

770

0

12

869

1

10

0.118

1.899

1,937

1,937

Martin

37117

37,117

59

1,549

2

883

1,849

1

1,033

0.219

2.130

1,938

1,938

Wake

37183

37,183

92

14,484

16

4,397

20,857

31

6,221

0.118

1.601

1,946

1,946

Madison

37115

37,115

58

765

2

5

926

2

3

0.155

1.781

1,947

1,947

Iredell

37097

37,097

49

4,139

4

1,144

5,400

5

1,305

0.069

1.201

1,948

1,948

Davie

37059

37,059

30

1,207

1

148

1,438

3

177

0.066

1.070

1,950

1,950

Alexander

37003

37,003

2

1,333

0

128

1,683

2

150

0.145

1.791

1,951

1,951

Davidson

37057

37,057

29

5,509

8

736

7,143

8

941

0.134

1.755

1,958

1,958

Burke

37023

37,023

12

3,573

5

326

4,314

15

407

0.100

1.331

1,962

1,962

Washington

37187

37,187

94

990

5

521

1,141

0

651

0.099

1.411

1,963

1,963

Tyrrell

37177

37,177

89

248

0

116

319

0

141

0.116

1.664

1,964

1,964

McDowell

37111

37,111

56

1,946

5

134

2,215

5

128

0.201

1.805

1,968

1,968

Randolph

37151

37,151

76

4,456

7

384

5,711

12

483

0.180

2.142

1,973

1,973

Chatham

37037

37,037

19

1,646

2

591

2,398

3

687

0.094

1.307

1,979

1,979

Wilson

37195

37,195

98

3,702

11

1,827

4,706

13

2,330

0.134

1.590

1,980

1,980

Rowan

37159

37,159

80

4,606

3

1,057

6,427

8

1,504

0.168

1.791

1,984

1,984

Pitt

37147

37,147

74

5,094

14

2,620

6,635

11

3,059

0.106

1.444

1,986

1,986

Catawba

37035

37,035

18

5,754

5

790

6,883

21

914

0.168

1.995

1,988

1,988

Buncombe

37021

37,021

11

7,515

9

930

9,956

18

1,206

0.207

1.851

1,989

1,989

Johnston

37101

37,101

51

3,999

6

1,165

4,780

13

1,349

0.144

1.690

1,996

1,996

Haywood

37087

37,087

44

2,110

2

57

2,463

8

62

0.094

3.640

2,000

2,000

Dare

37055

37,055

28

521

0

43

1,059

1

73

0.203

3.197

2,004

2,004

Beaufort

37013

37,013

7

2,692

7

1,131

2,909

4

1,163

0.141

2.316

2,013

2,013

Swain

37173

37,173

87

675

3

281

883

2

406

0.070

1.105

2,016

2,016

Greene

37079

37,079

40

870

4

534

1,178

4

664

0.065

1.093

2,026

2,026

Lee

37105

37,105

53

2,252

5

736

2,949

6

905

0.146

1.778

2,027

2,027

Rutherford

37161

37,161

81

2,992

12

495

3,543

8

576

0.142

1.655

2,029

2,029

Wayne

37191

37,191

96

6,638

18

2,593

8,227

23

3,073

0.154

1.680

2,030

2,030

Harnett

37085

37,085

43

3,776

6

1,051

4,789

10

1,453

0.118

1.506

2,032

2,032

Cleveland

37045

37,045

23

4,866

10

1,491

5,526

21

1,729

0.078

1.384

2,034

2,034

Lincoln

37109

37,109

55

2,216

8

302

2,817

7

350

0.125

1.601

2,039

2,039

Jackson

37099

37,099

50

1,143

2

215

1,504

5

307

0.181

1.980

2,040

2,040

Moore

37125

37,125

63

2,648

5

844

3,534

5

1,151

0.143

1.887

2,041

2,041

Mecklenburg

37119

37,119

60

21,588

44

8,027

30,757

35

11,631

0.091

1.321

2,042

2,042

Cabarrus

37025

37,025

13

4,099

3

856

5,669

20

1,203

0.130

1.732

2,044

2,044

Montgomery

37123

37,123

62

1,258

3

472

1,598

8

588

0.103

1.461

2,045

2,045

Stanly

37167

37,167

84

2,356

5

370

3,039

7

528

0.095

1.471

2,047

2,047

Henderson

37089

37,089

45

2,574

5

158

3,679

8

264

0.078

1.202

2,056

2,056

Graham

37075

37,075

38

415

0

40

488

1

45

0.104

1.548

2,065

2,065

Lenoir

37107

37,107

54

3,589

10

1,826

4,225

14

2,047

0.098

1.389

2,067

2,067

Transylvania

37175

37,175

88

1,173

3

92

1,401

4

104

0.091

1.470

2,068

2,068

Gaston

37071

37,071

36

9,014

11

1,523

11,455

26

2,194

0.060

1.036

2,071

2,071

Polk

37149

37,149

75

533

1

95

673

0

79

0.131

1.677

2,082

2,082

Macon

37113

37,113

57

797

0

9

1,157

3

22

0.241

2.214

2,083

2,083

Sampson

37163

37,163

82

3,025

4

1,396

3,447

4

1,524

0.082

1.388

2,085

2,085

Pamlico

37137

37,137

69

542

1

222

631

1

277

0.120

1.686

2,088

2,088

Cherokee

37039

37,039

20

1,027

2

32

1,173

1

42

0.172

1.835

2,090

2,090

Cumberland

37051

37,051

26

20,366

38

7,043

26,370

57

10,614

0.121

1.978

2,091

2,091

Jones

37103

37,103

52

578

1

297

650

2

305

0.163

1.716

2,095

2,095

Union

37179

37,179

90

3,915

4

1,034

5,273

9

1,348

0.138

1.621

2,096

2,096

Anson

37007

37,007

4

1,570

15

952

1,875

4

1,161

0.098

1.262

2,097

2,097

Hoke

37093

37,093

47

1,494

7

987

1,706

6

1,172

0.167

2.709

2,099

2,099

Hyde

37095

37,095

48

338

0

134

427

0

169

0.204

1.871

2,100

2,100

Duplin

37061

37,061

31

2,483

4

1,061

2,777

7

1,227

0.121

1.855

2,107

2,107

Richmond

37153

37,153

77

2,756

4

1,043

3,108

7

1,218

0.051

1.096

2,109

2,109

Clay

37043

37,043

22

284

0

1

419

0

5

0.177

2.916

2,119

2,119

Craven

37049

37,049

25

5,868

13

1,744

7,595

18

2,342

0.080

1.188

2,123

2,123

Scotland

37165

37,165

83

2,255

8

1,206

2,617

16

1,436

0.195

1.783

2,146

2,146

Onslow

37133

37,133

67

11,158

29

2,217

14,655

23

3,568

0.240

2.004

2,150

2,150

Robeson

37155

37,155

78

7,889

31

5,904

9,087

26

6,899

0.125

2.868

2,156

2,156

Carteret

37031

37,031

16

2,414

5

341

3,339

4

487

0.225

2.107

2,162

2,162

Bladen

37017

37,017

9

1,782

8

818

2,052

5

1,023

0.214

2.152

2,185

2,185

Pender

37141

37,141

71

1,228

4

580

1,602

3

763

0.240

2.365

2,232

2,232

Columbus

37047

37,047

24

3,350

15

1,431

4,144

17

1,832

0.042

0.999

2,238

2,238

New Hanover

37129

37,129

65

5,526

12

1,633

6,917

9

2,100

0.212

2.024

2,241

2,241

Brunswick

37019

37,019

10

2,181

5

659

2,655

6

841


Here’s an example citation: Kittredge (2026)1.

And a bit of ol Lorem ipsum:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

The end!