File: test-ggplot-spoke.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


df <- expand.grid(x = 1:10, y = 1:10)
df$angle <- runif(100, 0, 2*pi)
df$speed <- runif(100, 0, sqrt(0.1 * df$x))

p <- ggplot(df, aes(x, y)) +
  geom_spoke(aes(angle = angle), radius = 0.5)

test_that("Basic geom_spoke()", {
  
  l <- plotly_build(p)$x
  expect_length(l$data, 1)
  expect_equivalent(l$data[[1]]$type, "scatter")
  expect_equivalent(l$data[[1]]$mode, "lines")
  
  txt <- strsplit(l$data[[1]]$text, br())
  angle <- unlist(lapply(txt, function(x) x[grepl("angle", x, fixed = T)]))
  radius <- unlist(lapply(txt, function(x) x[grepl("radius", x, fixed = T)]))
  expect_equivalent(
    angle, rep(paste0("angle: ", format(df$angle)), each = 2)
  )
  expect_equivalent(
    unique(radius), "radius: 0.5"
  )
  
})

df$color <- rep(1:2, each = 50)
p <- ggplot(df, aes(x, y, color = color)) +
  geom_spoke(aes(angle = angle), radius = 0.5)

test_that("Basic geom_spoke() with color", {
  
  l <- plotly_build(p)$x
  # has to 3 traces since plotly.js doesn't (currently) support 
  # more than one `line.color`
  expect_length(l$data, 3)
  for (i in seq_along(l$data)) {
    expect_equivalent(l$data[[i]]$type, "scatter")
    expect_match(l$data[[i]]$mode, "markers|lines")
  }
  
})