Skip to content

Commit da64433

Browse files
committed
test line colors
1 parent c719333 commit da64433

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

inst/tests/test-ggplot-line.R

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

inst/tests/test-ggplot-linetype.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
context("line")
2+
3+
test_that("6 different automatic lty converted to plotly's 6 types", {
4+
d <- expand.grid(x=1:6, y=1:6)
5+
gg <- ggplot() +
6+
geom_line(aes(x=x, y=y, group=x, linetype=as.factor(x)), data=d)
7+
expected <-
8+
c("solid",
9+
"dash",
10+
"dot",
11+
"dashdot",
12+
"longdash",
13+
"longdashdot")
14+
info <- gg2list(gg)
15+
generated <- sapply(info[1:6], function(L) L$line$dash)
16+
expect_true(all(generated %in% expected))
17+
expect_true(all(expected %in% generated))
18+
})
19+
20+
test_that("different colored lines become different colored traces", {
21+
## http://stackoverflow.com/questions/2564258/plot-2-graphs-in-same-plot-in-r/19039094#19039094
22+
23+
## original data in a 'wide' format
24+
x <- seq(-2, 2, 0.05)
25+
y1 <- pnorm(x)
26+
y2 <- pnorm(x, 1, 1)
27+
df <- rbind(data.frame(x, variable="y1", value=y1),
28+
data.frame(x, variable="y2", value=y2))
29+
## plot, using the aesthetics argument 'colour'
30+
gg <- ggplot(data = df, aes(x = x, y = value, colour = variable))+
31+
geom_line()+
32+
scale_color_manual(values=c(y1="blue", y2="red"))
33+
info <- gg2list(gg)
34+
expect_equal(length(info), 3)
35+
expect_identical(info[[1]]$line$color, toRGB("blue"))
36+
n <- length(x)
37+
expect_identical(info[[1]]$y[1:n], y1)
38+
expect_identical(info[[1]]$x[1:n], x)
39+
expect_identical(info[[2]]$line$color, toRGB("red"))
40+
expect_identical(info[[2]]$y[1:n], y2)
41+
expect_identical(info[[2]]$x[1:n], x)
42+
})

0 commit comments

Comments
 (0)