Skip to content

Commit

Permalink
Merge pull request #166 from animint/maps-condition
Browse files Browse the repository at this point in the history
require(maps) in test
  • Loading branch information
tdhock authored Nov 12, 2024
2 parents 1e211ee + 850ab33 commit d7e9d9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: animint2
Title: Animated Interactive Grammar of Graphics
Version: 2024.11.2
Version: 2024.11.11
URL: https://animint.github.io/animint2/
BugReports: https://github.com/animint/animint2/issues
Authors@R: c(
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes in version 2024.11.11 (PR#166)

- if(require(maps)) in test-compiler-animation.R.

# Changes in version 2024.11.2 (PR#163)

- Added [gtable] to \link{gtable} to fix new CRAN issue (\link{} targets missing package anchors).
Expand Down
66 changes: 33 additions & 33 deletions tests/testthat/test-compiler-animation.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
acontext("animation")

library(maps)
library(plyr)
data(UStornadoes, package = "animint2")
stateOrder <- data.frame(state = unique(UStornadoes$state)[order(unique(UStornadoes$TornadoesSqMile), decreasing=T)], rank = 1:49) # order states by tornadoes per square mile
UStornadoes$state <- factor(UStornadoes$state, levels=stateOrder$state, ordered=TRUE)
UStornadoes$weight <- 1/UStornadoes$LandArea
# useful for stat_bin, etc.

USpolygons <- map_data("state")
USpolygons$state = state.abb[match(USpolygons$region, tolower(state.name))]

UStornadoCounts <-
ddply(UStornadoes, .(state, year), summarize, count=length(state))
tornado.anim <-
list(map=ggplot()+
geom_polygon(aes(x=long, y=lat, group=group),
data=USpolygons,
clickSelects="state",
fill="black", colour="grey") +
geom_segment(aes(x=startLong, y=startLat, xend=endLong, yend=endLat),
showSelected="year",
colour="#55B1F7", data=UStornadoes),
ts=ggplot()+
make_tallrect(UStornadoCounts, "year")+
geom_line(aes(year, count, group=state),
clickSelects="state",
data=UStornadoCounts, alpha=3/5, size=4),
time=list(variable="year",ms=2000))

test_that("tornado animation frames correct", {
info <- animint2dir(tornado.anim, open.browser=FALSE)
expect_identical(info$time$sequence, as.character(1950:2012))
})
if(require(maps) && require(plyr)){
data(UStornadoes, package = "animint2")
stateOrder <- data.frame(state = unique(UStornadoes$state)[order(unique(UStornadoes$TornadoesSqMile), decreasing=T)], rank = 1:49) # order states by tornadoes per square mile
UStornadoes$state <- factor(UStornadoes$state, levels=stateOrder$state, ordered=TRUE)
UStornadoes$weight <- 1/UStornadoes$LandArea
# useful for stat_bin, etc.
USpolygons <- map_data("state")
USpolygons$state = state.abb[match(USpolygons$region, tolower(state.name))]
UStornadoCounts <-
ddply(UStornadoes, .(state, year), summarize, count=length(state))
tornado.anim <- list(
map=ggplot()+
geom_polygon(aes(
x=long, y=lat, group=group),
data=USpolygons,
clickSelects="state",
fill="black", colour="grey") +
geom_segment(aes(
x=startLong, y=startLat, xend=endLong, yend=endLat),
showSelected="year",
colour="#55B1F7", data=UStornadoes),
ts=ggplot()+
make_tallrect(UStornadoCounts, "year")+
geom_line(aes(
year, count, group=state),
clickSelects="state",
data=UStornadoCounts, alpha=3/5, size=4),
time=list(variable="year",ms=2000))
test_that("tornado animation frames correct", {
info <- animint2dir(tornado.anim, open.browser=FALSE)
expect_identical(info$time$sequence, as.character(1950:2012))
})
}

## WorldBank/gapminder example.
data(WorldBank, package = "animint2")
Expand Down

0 comments on commit d7e9d9a

Please sign in to comment.