Skip to content

Commit 5bb5c03

Browse files
Copilotyihui-bot
andauthored
Fix broken coordinate/mark examples: parallel, radar, density, partition
Agent-Logs-Url: https://github.com/yihui/gglite/sessions/9467d468-1192-42f2-b4ac-6bc0270ab610 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
1 parent 5b0df96 commit 5bb5c03

File tree

9 files changed

+89
-67
lines changed

9 files changed

+89
-67
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: gglite
22
Title: Lightweight Data Visualization via the Grammar of Graphics
3-
Version: 0.0.1
3+
Version: 0.0.2
44
Authors@R: person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name",
55
comment = c(ORCID = "0000-0003-0645-5666"))
66
Description: A lightweight R interface to the AntV G2 JavaScript visualization

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# gglite 0.1
22

3+
- Fixed the `coordinate('parallel')` example to remove the broken `normalizeY`
4+
transform (which is not needed for parallel coordinates).
5+
6+
- Added working examples for `coordinate('radar')` and `coordinate('helix')`.
7+
8+
- Removed the broken `@examples` from `mark_density()` (the `kde` transform is
9+
not available in G2 v5) and `mark_partition()` (the `partition` mark does not
10+
work in G2 v5).
11+
12+
- Added parallel, radar, and helix sections to the coordinates example Rmd.
13+
314
A lightweight R interface to the
415
[AntV G2](https://g2.antv.antgroup.com/) JavaScript visualization library with
516
a ggplot2-style API. Create interactive charts using the Grammar of Graphics

R/coordinate.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#' transforms such as `'transpose'` (equivalent to ggplot2's `coord_flip()`) or
77
#' `'fisheye'`.
88
#'
9+
#' The `'radar'` and `'parallel'` coordinates require a `position` encoding
10+
#' (a character vector of column names) instead of separate `x`/`y` encodings.
11+
#'
912
#' @param chart A `g2` object.
1013
#' @param type Coordinate type string.
1114
#' @param ... Additional options such as `innerRadius`, `outerRadius`,
@@ -30,11 +33,19 @@
3033
#' mark_interval() |>
3134
#' coordinate('radial')
3235
#'
33-
#' # Parallel coordinate
36+
#' # Parallel coordinate (uses position encoding)
3437
#' g2(iris, position = c('Sepal.Length', 'Sepal.Width',
3538
#' 'Petal.Length', 'Petal.Width'), color = 'Species') |>
36-
#' mark_line(transform = list(list(type = 'normalizeY'))) |>
39+
#' mark_line() |>
3740
#' coordinate('parallel')
41+
#'
42+
#' # Radar coordinate (uses position encoding)
43+
#' df2 = data.frame(item = c('A', 'B', 'C', 'D', 'E'),
44+
#' score = c(3, 7, 2, 5, 4))
45+
#' g2(df2, position = c('item', 'score')) |>
46+
#' mark_line(style = list(closed = TRUE)) |>
47+
#' mark_point() |>
48+
#' coordinate('radar')
3849
coordinate = function(chart, type, ...) {
3950
chart$coords = c(list(type = type), list(...))
4051
chart

R/mark.R

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,12 @@ mark_boxplot = function(chart, ...) mark(chart, 'boxplot', ...)
248248

249249
#' Add a Density Mark
250250
#'
251-
#' A composite mark for kernel density estimation visualization.
251+
#' A composite mark for kernel density estimation visualization. Note that
252+
#' G2 v5 does not support the `kde` transform; use [mark_heatmap()] as an
253+
#' alternative for 2-D density visualizations.
252254
#'
253255
#' @inheritParams mark
254256
#' @export
255-
#' @examples
256-
#' g2(iris, x = 'Sepal.Width', y = 'Sepal.Length') |>
257-
#' mark_density(
258-
#' transform = list(list(type = 'kde')),
259-
#' style = list(fill = 'steelblue', fillOpacity = 0.5)
260-
#' )
261257
mark_density = function(chart, ...) mark(chart, 'density', ...)
262258

263259
#' Add a Heatmap Mark
@@ -435,21 +431,9 @@ mark_shape = function(chart, ...) mark(chart, 'shape', ...)
435431

436432
#' Add a Partition (Sunburst) Mark
437433
#'
434+
#' Note: the `partition` mark may not work correctly in G2 v5. Consider using
435+
#' [mark_treemap()] as an alternative for hierarchical data visualization.
436+
#'
438437
#' @inheritParams mark
439438
#' @export
440-
#' @examples
441-
#' tree_data = list(
442-
#' name = 'root', children = list(
443-
#' list(name = 'A', value = 10, children = list(
444-
#' list(name = 'A1', value = 5), list(name = 'A2', value = 5)
445-
#' )),
446-
#' list(name = 'B', value = 20)
447-
#' )
448-
#' )
449-
#' g2() |>
450-
#' mark_partition(
451-
#' data = list(value = tree_data),
452-
#' encode = list(value = 'value'),
453-
#' coordinate = list(type = 'theta', innerRadius = 0.3)
454-
#' )
455439
mark_partition = function(chart, ...) mark(chart, 'partition', ...)

examples/coordinates.Rmd

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,45 @@ g2(df, x = 'x', y = 'y', color = 'x') |>
8686
coordinate('radial', innerRadius = 0.3)
8787
```
8888

89+
## Parallel
90+
91+
Maps multiple numeric variables to parallel axes. Use a `position`
92+
encoding (a character vector of column names) instead of `x`/`y`.
93+
94+
```{r}
95+
g2(iris, position = c('Sepal.Length', 'Sepal.Width',
96+
'Petal.Length', 'Petal.Width'), color = 'Species') |>
97+
mark_line() |>
98+
coordinate('parallel')
99+
```
100+
101+
## Radar
102+
103+
Displays data on radial axes emanating from a center point. Like
104+
parallel coordinates, radar charts require a `position` encoding.
105+
106+
```{r}
107+
df_radar = data.frame(
108+
item = c('A', 'B', 'C', 'D', 'E'),
109+
score = c(3, 7, 2, 5, 4)
110+
)
111+
g2(df_radar, position = c('item', 'score')) |>
112+
mark_line(style = list(closed = TRUE)) |>
113+
mark_point() |>
114+
coordinate('radar')
115+
```
116+
117+
## Helix
118+
119+
Arranges data along a helix spiral.
120+
121+
```{r}
122+
df_helix = data.frame(x = 1:50, y = sin(1:50 / 5))
123+
g2(df_helix, x = 'x', y = 'y') |>
124+
mark_line() |>
125+
coordinate('helix')
126+
```
127+
89128
## Transpose (coord_flip)
90129

91130
Swap x and y axes, equivalent to ggplot2's `coord_flip()`. This is a

man/coordinate.Rd

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/g2_col_cdn.Rd

Lines changed: 0 additions & 15 deletions
This file was deleted.

man/mark_density.Rd

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mark_partition.Rd

Lines changed: 2 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)