Please use animint2 instead.
tdhock / animint Goto Github PK
View Code? Open in Web Editor NEWanimated and interactive web graphics
animated and interactive web graphics
Please use animint2 instead.
I think it's better to add test coverage reports for animint. The covr package can accomplish such a task.
I haven't had time yet to figure out why this is happening but I saw the good blocks page, and this on the R console:
> animint2gist(viz)
Loading required namespace: gistr
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Loading required namespace: RSelenium
Cloning into '/tmp/RtmpNoLwRA/gist-36dc08ace6bd39f8693e'...
remote: Counting objects: 1989, done.
remote: Compressing objects: 100% (1989/1989), done.
remote: Total 1989 (delta 674), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (1989/1989), 448.13 KiB, done.
Resolving deltas: 100% (674/674), done.
Error in find_test_path() : animint must appear somewhere in 'dir'
> traceback()
7: stop("animint must appear somewhere in 'dir'")
6: find_test_path()
5: file.path(find_test_path(), "pids.txt")
4: pid_file()
3: unlink(pid_file())
2: tests_exit()
1: animint2gist(viz)
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_CA.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] graphics utils datasets grDevices stats methods base
other attached packages:
[1] data.table_1.9.5 animint_2015.05.20 proto_0.3-10 RColorBrewer_1.0-5
[5] lattice_0.20-31 plotly_0.5.27 ggplot2_1.0.1 RJSONIO_1.3-0
[9] RCurl_1.95-4.1 bitops_1.0-6
loaded via a namespace (and not attached):
[1] Rcpp_0.11.4 compiler_3.2.0 formatR_1.0 plyr_1.8.1
[5] tools_3.2.0 digest_0.6.4 jsonlite_0.9.13 evaluate_0.5.5
[9] gtable_0.1.2 DBI_0.3.1 parallel_3.2.0 stringr_0.6.2
[13] dplyr_0.4.0 httr_0.6.1 knitr_1.9 caTools_1.16
[17] grid_3.2.0 R6_2.0 XML_3.98-1.1 RSelenium_1.3.5
[21] rmarkdown_0.3.3 reshape2_1.2.2 gistr_0.2.0 magrittr_1.0.0
[25] scales_0.2.3 htmltools_0.2.6 MASS_7.3-40 assertthat_0.1
[29] dichromat_2.0-0 colorspace_1.2-4 httpuv_1.3.2 labeling_0.2
[33] munsell_0.4.2 chron_2.3-45
The ggthemes package provides some additional themes for ggplot2. But some of them don't seem to work with animint.
animint2dir(list(p1 = qplot(Sepal.Width, Sepal.Length, data = iris, colour = Species) + theme_fivethirtyeight()))
Error in serialize(object, connection = NULL, ascii = ascii) :
object 'direction' not found
Traceback shows that the error occurs when using guides_train()
in getLegendList()
4 ggplot2:::guides_train(scales = scales, theme = theme, guides = guides.list,
labels = plot$labels) at animint.R#1127
3 getLegendList(meta$built) at animint.R#209
2 parsePlot(meta) at animint.R#929
1 animint2dir(list(p1 = qplot(Sepal.Width, Sepal.Length, data = iris,
colour = Species) + theme_fivethirtyeight()))
This error occurs for the following themes:
theme_calc()
theme_fivethirtyeight()
theme_gdocs()
theme_wsj()
This is a new aesthetic in ggplot2 v2.0 that we can use to render the css stroke-width property
geom_point() gains a stroke aesthetic which controls
the border width of shapes 21-25 (#1133, @SeySayux).
size and stroke are additive so a point with size = 5 and
stroke = 5 will have a diameter of 10mm. (#1142)
https://github.com/hadley/ggplot2/blob/master/NEWS.md#ggplot2-200
Legend interactivity works fine when creating a standalone page:
library(animint)
p <- qplot(data = iris, x = Sepal.Width, y = Sepal.Length, color = Species)
animint2gist(list(p = p))
However, something goes haywire when I try to embed in R markdown.
Any thoughts, @kferris10 ?
Does anybody know why the legends are getting pushed beneath the plot at this link? Is this something I'm doing wrong?
http://kferris10.github.io/AnimintBlog/World-Population-by-Income-Choropleth-with-animint/
I made some modifications animint.js to accommodate the new chunk file structure: common chunk and varied chunks in the big-chunks
branch.
Currently the animint render works well for all visualizations without time animation; however, when I render the viz in test-WorldBank-good-with-time.R
https://github.com/caijun/AnimintTest/blob/master/dev/test-WorldBank-good-with-time.R
once animation begins, the third plot in the viz has the problem of Downloading geom6_bar_bar6.tsv
.
I further looked at firebug and saw following error.
I am pretty sure that this error caused in following modifications added by myself:
https://github.com/tdhock/animint/blob/big-chunks/inst/htmljs/animint.js#L749-L758
Before animation starts, the viz still works well. Once animation starts and the geom needs to be updated by calling update_geom
. At this point, all chunks including the common chunk should have been downloaded and saved into g_info.data
. So for the following pieces of code in update_geom
function
if(g_info.data.hasOwnProperty(tsv_name)){
draw_panels(g_info, g_info.data[tsv_name], selector_name);
}else{
g_info.tr.select("td.status").text("downloading");
var svg = SVGs[g_name];
var loading = svg.append("text")
.attr("class", "loading"+tsv_name)
.text("Downloading "+tsv_name+"...")
.attr("font-size", 9)
//.attr("x", svg.attr("width")/2)
.attr("y", 10)
.style("fill", "red");
download_chunk(g_info, tsv_name, function(chunk){
// copy data from common tsv to varied tsv
if (g_info.common_tsv) {
var common_chunk = g_info.data[g_info.common_tsv];
chunk = copy_chunk(common_chunk, chunk, g_info.columns.common);
g_info.data[tsv_name] = chunk;
}
loading.remove();
draw_panels(g_info, chunk, selector_name);
});
}
Only the if
branch will be exectued and the else
branch will not be executed in this situation, if my understanding for the code is correct. Hence, there should not be any problem of downloading chunk when animation starts. I am working on it for several days, but am still not able to figure out the how this problem occurred.
Could any of you have a look at this example and help me locate where the bug comes. Thanks. @tdhock
First I would like to thank you for developing this package. I have just started creating some graphs and it is working very smoothly. The simplicity of this package is a huge strength and is much appreciated!
I have one smaller issue: The size of text displayed in R and in Firefox is not the same. It seems geom_text does not vary with size.
I have created this simple example:
library(animint)
data(WorldBank)
wb <- WorldBank[WorldBank$year == 2010,]
p <- ggplot() + geom_point(data=wb, aes(y=fertility.rate, x=life.expectancy))
p <- p + geom_text(data=wb, aes(y=fertility.rate, x=life.expectancy, label=iso2c, size=population)) + scale_size_continuous(range=c(3,10))
p
gg2animint(list(plot1=p))
The size of the labels should vary according to population size and this works fine in R but not in Firefox.
Thanks again!
For example, when I use animint2dir
from current master branch to produce WorldBank viz,
library(animint)
data(WorldBank, package = "animint")
WorldBank$region <- gsub("(all income levels)", "", WorldBank$region, fixed = TRUE)
ts <- ggplot() +
make_tallrect(WorldBank, "year") +
# plot the lines *on top of rectangles* so lines are clickable
geom_line(aes(year, life.expectancy, group = country, colour = region,
clickSelects = country),
data = WorldBank, size = 4, alpha = 3/5) +
guides(color = "none")
not.na <- subset(WorldBank, !(is.na(life.expectancy) | is.na(fertility.rate)))
scatter <- ggplot() +
geom_point(aes(fertility.rate, life.expectancy, clickSelects = country,
showSelected = year, colour = region, size = population,
key = country), # key aesthetic for animated transitions!
data = not.na) +
geom_text(aes(fertility.rate, life.expectancy, label = country,
showSelected = country, showSelected2 = year,
key = country), #also use key here!
data = not.na) +
scale_size_animint(breaks = 10^(5:9)) +
make_text(WorldBank, 5, 85, "year")
ts <- ts + theme_animint(width = 360, height = 360)
scatter <- scatter + theme_animint(width = 360, height = 360)
getPlotList <- list(time = list(variable = "year", ms = 3000),
duration = list(year = 1000),
first = list(year = 1975, country = c("United States", "Vietnam")),
selector.types = list(country = "multiple"),
# the plots we constructed earlier
ts = ts,
scatter = scatter)
animint2dir(getPlotList, out.dir = "shiny")
it produces following error
Error in time.classes[[1]] : subscript out of bounds
This viz comes from the index.Rmd
under the directory example/rmarkdown
. I am working on it to fix it.
I recently updated all my packages to their most up-to-date versions. Now, when running a piece of animint code that previously worked flawlessly, I am receiving the error "animint.width is not a valid theme element name."
After reading issue #29 (#29), I attempted the solution of moving the call to theme_animint above the other ggplot theme calls being used in conjunction, but I still receive the error.
As described here
https://gist.github.com/srvanderplas/bc18219e50349c91c061
Line tooltips are not currently working in animint. I'm guessing this is because of the issues with path mapping as opposed to simple aesthetics, but have not had time to explore further.
Benefits of using phantomjs (over, say, firefox) for testing:
Drawbacks:
Just did a fresh install on OS X and tried a few things. Any plot gives me the same error:
e.g.
> animint2dir(list(p = qplot(1:10)))
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Error in if (remove.group) "group" :
missing value where TRUE/FALSE needed
noticed its in your DESCRIPTION file as a Suggest...
Hi there,
I am using animint library as I need interactive graphs over ggplot2 graphs.
I find animint very useful for this.
However I have a requirement where I need to use stat_smooth with method = "loess".
Like the following code in R draws a nice line. Is it possible to do the same in animint?
c <- ggplot(mtcars, aes(qsec, wt))
c + stat_smooth(method = "loess")+geom_point()
Please let me know if this is possible and if yes then how I should structure the code.
Many Thanks,
Manami.
Does anybody know why there might be problems with the tooltips at the end of this post?
If I take out the aes(href = links)
argument, the points render just fine.
Hi
How do I stop the download/status table appearing in the final web page?
I can see it's in the animint.js Javascript but I'm an R/ggplot person rather than a Javascript one.
Paul
Rotating axis text is not working with animint
fg=ggplot() + geom_point(aes(x=State, y=Prop.Inv, showSelected=Year), data=ss) + theme_animint(width=600, height=400) + theme(axis.text.x=element_text(angle=70, hjust=1))
sg=ggplot() + stat_summary(data=ss, aes(Year, Year, clickSelects=Year), fun.y=length, geom="bar")
map=list(fg=fg, sg=sg)
animint2dir(map ,out.dir="animint")
doesn't rotate the text on x axis.
While if I simply plot fg
the text in x-axis is rotated but when combine plots with animint2dir
the text in x-axis is horizontal.
It was a little unintuitive, at least to me, that library(knitr) is required to be ran when using knitr and R Markdown to create an HTML page. The reason being is that in the past I have never had to run library(knitr) in my code in order to Knit a page, mostly because I had never used animint before.
If one of the tsv files is more than 1MB, then gist will "truncate" it (only send the first 1MB). https://developer.github.com/v3/gists/#truncation
TODO
For example this gist has some files which are truncated https://api.github.com/gists/9414d390fd7647f9fc8a
Specify stroke-opacity and fill-opacity separately (allowing rectangles to have no fill but still have a border, etc.). These options are available in d3 but are not currently ggplot2 aesthetics.
The current barrier to implementing aes(hoverSelects)
is that we don't have any way to test it using RSelenium ropensci/RSelenium#59
For single selection variables I propose that mouseover should call update_selector and mouseout should do nothing.
Would it be useful to combine hoverSelects with a multiple selection variable? Anybody know of any examples?
When using theme_bw() (or theme_grey, etc.), the theme_animint() statement has to come before any other theme set:
library(animint)
library(ggplot2)
df <- data.frame(x=rnorm(50), y=rnorm(50))
p1 <- ggplot() +
geom_point(data=df, aes(x=x, y=y)) +
theme_animint(width=500, height=500)
animint2dir(list(p=p1))
works fine, but
p2 <- ggplot() +
geom_point(data=df, aes(x=x, y=y)) +
theme_bw() +
theme_animint(width=500, height=500)
produces the error
> p2 <- ggplot() +
+ geom_point(data=df, aes(x=x, y=y)) +
+ theme_bw() +
+ theme_animint(width=500, height=500)
Error in (function (el, elname) :
"animint.width" is not a valid theme element name.
This error does not occur when theme_animint() is used before theme_bw():
p3 <- ggplot() +
geom_point(data=df, aes(x=x, y=y)) +
theme_animint(width=500, height=500) +
theme_bw()
I'm toying around creating a correlation matrix linked to scatterplots (source and output). Some thoughts I had:
(1) Multiple clickSelects would make this easier and more efficient
(2) This has me convinced dynamic x/y scales is at least worth exploring. Part of me thinks we should not even worry about converting ggplot2 axes and just create/update them ourselves in the renderer.
Hi all,
I just was browsing the R bloggers and noticed that Hadley Wickham had released the svglite package. I come up with an idea: the svglite may help to simplify the compiler and renderer of animint as it can save an R plot into a svg file, which can be easily embedded into html and manipulated by d3.
Taking the g1
plot from SimpleGeoms.R
in the examples
directory as an example, we can easily export the plot into a svg file named tmp.svg
.
library(svglite)
library(ggplot2)
svglite(file = "~/Desktop/tmp.svg")
xydata <- data.frame(x=sort(runif(50, 0, 10)))
xydata$y <- 3+2*xydata$x + rnorm(50, 0, 1)
g1 <- ggplot() + geom_point(data=xydata, aes(x=x, y=y)) +
geom_abline(data=data.frame(intercept=c(3, 0), slope=c(2,1)), aes(intercept=intercept, slope=slope)) +
ggtitle("geom_abline")
g1
dev.off()
I think svglite can at least help us simplify the code to draw simple geoms and support more aesthetics such as shape and arrow, which haven't been fully implemented in animint. For example,
# arrow aesthetic
library(grid)
svglite(file = "~/Desktop/arrow1.svg")
c <- ggplot(economics, aes(x = date, y = pop))
c + geom_line(arrow = arrow())
dev.off()
svglite(file = "~/Desktop/arrow2.svg")
c <- ggplot(economics, aes(x = date, y = pop))
c + geom_line(
arrow = arrow(angle = 15, ends = "both", type = "closed")
)
dev.off()
# shape aesthetic
svglite(file = "~/Desktop/shape1.svg")
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(aes(shape = factor(cyl)))
dev.off()
svglite(file = "~/Desktop/shape2.svg")
pchShow <-
function(extras = c("*",".", "o","O","0","+","-","|","%","#"),
cex = 3, ## good for both .Device=="postscript" and "x11"
col = "red3", bg = "gold", coltext = "brown", cextext = 1.2,
main = paste("plot symbols : points (... pch = *, cex =",
cex,")"))
{
nex <- length(extras)
np <- 26 + nex
ipch <- 0:(np-1)
k <- floor(sqrt(np))
dd <- c(-1,1)/2
rx <- dd + range(ix <- ipch %/% k)
ry <- dd + range(iy <- 3 + (k-1)- ipch %% k)
pch <- as.list(ipch) # list with integers & strings
if(nex > 0) pch[26+ 1:nex] <- as.list(extras)
plot(rx, ry, type = "n", axes = FALSE, xlab = "", ylab = "", main = main)
abline(v = ix, h = iy, col = "lightgray", lty = "dotted")
for(i in 1:np) {
pc <- pch[[i]]
## 'col' symbols with a 'bg'-colored interior (where available) :
points(ix[i], iy[i], pch = pc, col = col, bg = bg, cex = cex)
if(cextext > 0)
text(ix[i] - 0.3, iy[i], pc, col = coltext, cex = cextext)
}
}
pchShow()
dev.off()
As shown in above code and figures, svglite can save not only ggplots but also ordinary plots into svgs. This makes rendering any aesthetics in R plots in html possible. Hence, with svglite, we can focus on the added keywords rather than drawing geoms.
Further, svglite may be useful in storing the chunk files.
@tdhock how do you like adopting svglite in animint?
The package looks interesting. I installed the version of ggplot2
from github and then tried to run example from one of your guides and get the following error:
> if (!require("servr")) install.packages("servr")
Loading required package: servr
> gg2animint(list(plot1 = g1), out.dir = "g1")
opening a web browser with a file:// URL; if the web page is blank, try running
if (!require("servr")) install.packages("servr")
servr::httd("C:/R/R-3.1.1/bin/i386/g1")
Error in shell.exec(url) : 'g1/index.html' not found
In addition: Warning message:
In gg2animint(list(plot1 = g1), out.dir = "g1") :
gg2animint is deprecated, use animint2dir instead
I also tried gg2animint(list(plot1 = g1), out.dir = "g1")
but same error. Here g1
rendered in the default gui as expected. Not sure of the reason for this but I can't seem to get any of the plots working. Could be an issue with my machine set up so I included sessionInfo
below. The error indicates the problem occurs with a call to servr::httd("C:/R/R-3.1.1/bin/i386/g1")
. The directory g1
was created at the point in the filepath but clicking on index.html reveals a blank page.
Session Info
R version 3.1.1 (2014-07-10)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] servr_0.1 plyr_1.8.1 animint_2014.8.25 proto_0.3-10 ggplot2_0.9.3.1.99
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 devtools_1.5 digest_0.6.4 evaluate_0.5.5 formatR_0.10 grid_3.1.1 gtable_0.1.2
[8] httpuv_1.3.0 httr_0.3 knitr_1.6 labeling_0.2 MASS_7.3-33 memoise_0.2.1 munsell_0.4.2
[15] pacman_0.2.0 parallel_3.1.1 Rcpp_0.11.2 RCurl_1.95-4.1 reshape2_1.4 RJSONIO_1.3-0 scales_0.2.4
[22] stringr_0.6.2 tools_3.1.1 whisker_0.3-2
>
Also tried animint2dir
:
> animint2dir(list(plot1 = g1), out.dir = "g1")
opening a web browser with a file:// URL; if the web page is blank, try running
if (!require("servr")) install.packages("servr")
servr::httd("C:/Users/trinker/Desktop/g1")
Error in shell.exec(url) : 'g1/index.html' not found
Here's a LINK to the output files.
Consider the following:
library(dplyr)
library(animint)
library(pitchRx)
data(pitches, package = "pitchRx")
dat <- pitches %>%
mutate(dated = as.Date(date, format = "%Y_%m_%d")) %>%
group_by(pitch_type, pitcher_name, dated) %>%
summarise(count = n()) %>% data.frame
series <- ggplot(data = dat, aes(x = dated, y = count)) +
geom_line(aes(color = pitch_type, linetype = pitcher_name))
series
Now consider the resulting animint plot.
animint2gist(list(a = series))
There are a couple things wrong here:
(1) The colors and linetypes are not drawn correctly
(2) The x-axis is not drawn correctly
Even more worrisome, if we add a group aesthestic, ggplot2 returns the same plot, but animint throws an error:
series2 <- ggplot(data = dat3, aes(x = dated, y = count)) +
geom_line(aes(color = pitch_type, linetype = pitcher_name,
group = interaction(pitch_type, pitcher_name)))
animint2dir(list(b = series2))
Error in if (length(geom.aes.vars) > 0 & nrow(g.data) != nrow(l$data) & :
argument is of length zero
Hi there!
The implementation of facet_wrap in animint is working great, and for the most part looks really fantastic, so thanks for that. However, I am running into a small issue where the sub-titles on a faceted plot are overlapping with the main title.
For example, here's what my plot looks like with a faceted plot in animint:
As you can see, there's some overlap going on. I'm not 100% sure that this is an issue with animint or just with my use of it, but when I run the same plot just using ggplot, I get this:
Thanks so much for any help you can give.
Best,
Nathan
The animation can be paused for 2 reasons: (1) the user clicked the pause button, or (2) the user hides the animint browser window.
Currently, in both cases the animation will begin to play again if the user shows the browser window. This is annoying when debugging an animation.
The correct behavior should be: when the user shows the browser window after having hidden it, begin to play again in case (2), but not in case (1). For case (1), the user should have to click the play button to resume the animation.
We will have to edit the animint.js renderer to keep track of how the animint was paused, via (1) or (2) -- currently it does not keep track of how, it just pauses the animation in both cases.
I've started making some fixes for plotly, so y'all might be interested in following along since some similar fixes will be needed here
To reduce the initial choppiness of animation like this, it would be nice to have a programmatic way to pause the animation by default (so the user can wait until all the necessary data is loaded before starting the animation).
A better solution might be to dynamically pause the animation until a certain number of chunks have been loaded.
Note that I've tried the chunk_vars=character()
trick to prevent data from being split into chunks, but I received this error:
I run the test-passed test-hjust-text-anchor.R
with tests_run(filter = "hjust-text-anchor")
. It fails with following error
1. Error: geom_text(hjust=1) => <text style="text-anchor: end"> --------------------------------------------------
subscript out of bounds
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: getStyleValue(info$html, "//g[@class=\"geom8_text_objective\"]//text", "text-anchor") at test-hjust-text-anchor.R:99
5: xmlAttrs(nodes[[1]]) at test-hjust-text-anchor.R:82
2. Error: geom_text(hjust=0.5) => <text style="text-anchor: middle"> ---------------------------------------------
subscript out of bounds
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls)
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: getStyleValue(info$html, "//g[@class=\"geom8_text_objective\"]//text", "text-anchor") at test-hjust-text-anchor.R:107
5: xmlAttrs(nodes[[1]]) at test-hjust-text-anchor.R:82
I tranck the code and find that info$html
is different from what I tested before. https://github.com/tdhock/animint/blob/master/tests/testthat/test-hjust-text-anchor.R#L91
I debug the test using following code
Browse[3]> xpath
[1] "//g[@class=\"geom8_text_objective\"]//text"
Browse[3]> getNodeSet(html, xpath)
list()
attr(,"class")
[1] "XMLNodeSet"
Browse[3]> getNodeSet(html, "//g[@class=\"geom8_text_objective\"]")
[[1]]
<g class="geom8_text_objective">
<g class="PANEL1"/>
</g>
attr(,"class")
[1] "XMLNodeSet"
No geom.text
is contained in PANEL1
in the info$html
. I also export info$html
to file and no text.geom
is found. But opening the index.html
directly in Firefox, it does have.
I guess it may be due to use PhantomJS instead of Selenium. @cpsievert
when I do animint2gist I get redirected to gist.github.com.
for example I just made this one
https://gist.github.com/tdhock/3020adccac547f892c26
which should have been
http://bl.ocks.org/tdhock/raw/3020adccac547f892c26/
My output at the command line is
> animint2gist(wb.facets)
Loading required namespace: gistr
Loading required package: rjson
Your gist has been published
View gist at https://gist.github.com/tdhock/3020adccac547f892c26
Embed gist with <script src="https://gist.github.com/tdhock/3020adccac547f892c26.js"></script>
Error in gist$id : $ operator is invalid for atomic vectors
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rjson’
> animint2gist
function (plot.list, url_prefix = "http://bl.ocks.org", description = plot.list$title,
screenshot = TRUE, ...)
{
if (!is.character(description) || length(description) ==
0)
description <- ""
if (length(description) > 1)
description <- description[[1]]
res <- animint2dir(plot.list, open.browser = FALSE, ...)
if (!requireNamespace("gistr")) {
stop("Please run \n", "devtools::install_github('rOpenSci/gistr')",
"before using this function")
}
vendor.path <- file.path(res$out.dir, "vendor")
vendor.files <- list.files(vendor.path)
vendor.path.files <- file.path(vendor.path, vendor.files)
copied <- file.copy(vendor.path.files, file.path(res$out.dir,
vendor.files))
file.remove(vendor.path.files)
file.remove(vendor.path)
index.file <- file.path(res$out.dir, "index.html")
html <- readLines(index.file)
html <- gsub("vendor/", "", html)
cat(html, file = index.file, sep = "\n")
all.files <- Sys.glob(file.path(res$out.dir, "*"))
all.file.info <- file.info(all.files)
is.empty <- all.file.info$size == 0
is.tilde <- grepl("~$", all.files)
is.png <- grepl("[.]png$", all.files)
is.ignored <- all.file.info$isdir | is.empty | is.tilde
is.ignored <- is.ignored | is.png
to.post <- all.files[!is.ignored]
gist <- gistr::gist_create(to.post, description = description,
browse = FALSE, ...)
if (interactive())
gist
################### What are these previous 2 lines doing?
if (!isTRUE(as.list(match.call())$open.browser == FALSE))
browseURL(file.path(url_prefix, gist$id))
has.cmds <- all(Sys.which(c("git", "phantomjs")) != "")
has.selenium <- requireNamespace("RSelenium")
if (has.cmds && has.selenium && screenshot) {
cloned.dir.base <- paste0("gist-", gist$id)
cloned.dir <- file.path(tempdir(), cloned.dir.base)
clone.cmd <- sprintf("git clone [email protected]:%s.git %s",
gist$id, cloned.dir)
system(clone.cmd)
tests_exit()
pJS <- RSelenium::phantom()
on.exit(pJS$stop(), add = TRUE)
Sys.sleep(5)
dr <- RSelenium::remoteDriver(browserName = "phantomjs")
dr$open(silent = TRUE)
if (isTRUE(dr$value$takesScreenshot)) {
raw <- file.path("http://bl.ocks.org", gist$owner$login,
"raw", gist$id)
dr$navigate(raw)
screenfile <- file.path(cloned.dir, "screenshot.png")
dr$screenshot(file = screenfile)
thumbnail <- file.path(cloned.dir, "thumbnail.png")
cmd <- sprintf("convert %s -trim -resize 230 %s",
screenfile, thumbnail)
status <- system(cmd)
if (status != 0) {
file.copy(screenshot, thumbnail)
}
git.cmds <- paste("cd", cloned.dir, "&&", "git add thumbnail.png &&",
"git commit thumbnail.png -m thumbnail &&", "git push")
system(git.cmds)
}
thumb.url <- sprintf("https://gist.github.com/%s#file-thumbnail-png",
gist$id)
message("pushed thumbnail.png from ", cloned.dir, " to ",
thumb.url)
}
gist
}
<environment: namespace:animint>
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_CA.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] graphics utils datasets grDevices stats methods base
other attached packages:
[1] RSelenium_1.3.5 XML_3.98-1.1 animint_2015.03.31
[4] proto_0.3-10 testthat_0.9.1.9001 RColorBrewer_1.0-5
[7] lattice_0.20-31 plotly_0.5.27 ggplot2_1.0.0.99
[10] RJSONIO_1.3-0 RCurl_1.95-4.1 bitops_1.0-6
loaded via a namespace (and not attached):
[1] Rcpp_0.11.4 knitr_1.9 MASS_7.3-40 munsell_0.4.2
[5] colorspace_1.2-4 httr_0.2 stringr_0.6.2 plyr_1.8.1
[9] caTools_1.16 tools_3.2.0 dichromat_2.0-0 grid_3.2.0
[13] gtable_0.1.2 gistr_0.0.2 assertthat_0.1 digest_0.6.4
[17] crayon_1.1.0 reshape2_1.2.2 formatR_1.0 evaluate_0.5.5
[21] labeling_0.2 compiler_3.2.0 scales_0.2.3
>
> tests_init()
Error in loadNamespace(name) : there is no package called ‘rstudio’
Calls: <Anonymous> ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
[ERROR - 2015-05-22T16:04:29.168Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1432310669132
:262 in error
Error: Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.
class: org.openqa.selenium.NoSuchElementException
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RSelenium_1.3.5 XML_3.98-1.1 RJSONIO_1.3-0 RCurl_1.95-4.6 bitops_1.0-6
[6] testthat_0.9.1 animint_2015.05.21 proto_0.3-10 ggplot2_1.0.1
loaded via a namespace (and not attached):
[1] Rcpp_0.11.6 magrittr_1.5 devtools_1.8.0 MASS_7.3-40 munsell_0.4.2 colorspace_1.2-6
[7] stringr_1.0.0 plyr_1.8.2 caTools_1.17.1 tools_3.2.0 grid_3.2.0 gtable_0.1.2
[13] git2r_0.10.1 rversions_1.0.0 digest_0.6.8 reshape2_1.4.1 memoise_0.2.1 stringi_0.4-1
[19] scales_0.2.4
would be nice to actually draw two strips rather than the current hack which renders one strip with "foo ; bar"
I've been putting together an example with the pirates dataset the last couple days. I thought I'd post the current version here to see if you have any thoughts before adding it to the animint examples.
I also noticed a couple of issues that I wanted to bring up. Here's what my ggplot2 version of the binned plot looks like.
There's a couple of things that don't transfer to animint:
theme(panel.background = element_rect(fill = "lightblue"))
. Is there currently a way to get animint to color the background?geom_tile(aes(...), colour = "red", data = p_df3)
but animint isn't drawing the edges.As noted here, geom_abline()
isn't working. Here is a mini-example:
library(animint)
p <- qplot(wt, mpg, data = mtcars) + geom_abline(intercept = 20)
animint2dir(list(p = p))
I mentioned this in another issue but felt it best to open a new issue as that problem had been resolved. This makes the issues section more searchable for others.
I am attempting to include animint
rendered visuals in knitr
or new rmarkdown
. Here was the direction I was given:
Here is a minimal knitr example. The error might be a weird Windows OS/browser issue with
browseURL
. Does this run without error?
browseURL("C:/Users/trinker/Desktop/WorldBank-viz/g1/index.html")
Yesterday I started seeing File not found for certain animints, so I emailed Mike Bostock to see if he could help:
Dear Mike, thanks for your very useful bl.ocks.org service, which I have been using to share D3 data visualizations.
Today I got a "File not found." message for http://bl.ocks.org/tdhock/raw/9414d390fd7647f9fc8a/ which I thought was strange since (1) it was working last week, and (2) the gist is still available at
https://gist.github.com/tdhock/9414d390fd7647f9fc8a
Even more strangely, this does not affect all of my gists. You can see on my blocks index page http://bl.ocks.org/tdhock that there are in fact a few that are still working.
By comparing my list of blocks to my list of gists https://gist.github.com/tdhock/ you can see that the next data viz which stopped working is
http://bl.ocks.org/tdhock/raw/2120199e9576d3628537/
Any idea about why this problem is occuring, and how to fix it?
Maybe it actually a bug in the Gist API? What API call are you using to determine whether or not there should be a blocks entry?
Thanks in advance for any help you can provide.
He responded by explaining how he determines if a gist should be a block:
To be displayed as a block, at least one of the following files must be present:
* index.html
* README.md
From the analysis here https://github.com/tdhock/gist-bug it seems like the problem is a new maximum of 40 files per gist.
I will file a GitHub support request.
seems like travis will assume the build has problems and kill it if it goes more than 10 minutes with no output. http://docs.travis-ci.com/user/build-timeouts/#Build-times-out-because-no-output-was-received says that one way to fix that is with the travis_wait command. Could we add that in front of R CMD check?
otherwise maybe instead of R CMD check we could run something like R -e 'library(animint);tests_init();tests_run()' and then put print statements into animint2HTML?
http://www.htmlwidgets.org/develop_intro.html
We should seriously consider getting HTMLWidget bindings for animint; this might allow us to zoom, etc. and interact with other JS libraries.
There are also some really handy functions that may be useful for us: http://www.htmlwidgets.org/develop_advanced.html#dataframetod3
We may be able to simplify the rendering/conversion by using dataframetod3() instead of writing a bunch of json files.
I'm trying to familiarize myself with the testing workflow for animint. @cpsievert has pointed me to the testing wiki to get started, but I have been unable to run tests_init()
without an error.
> library(animint)
> tests_init()
Starting phantomjs binary. To shut it down, run:
pJS$stop()
Error: Summary: NoSuchElement
Detail: An element could not be located on the page using the given search parameters.
class: org.openqa.selenium.NoSuchElementException
It also spits out some warning messages which Carson said not to worry about. If I try using Firefox, I get a different error:
> tests_init("firefox")
Undefined error in RCurl call.
Starting selenium binary. To shut it down, run:
remDr$closeWindow()
remDr$closeServer()
Undefined error in RCurl call.
Error in queryRD(paste0(serverURL, "/session"), "POST", qdata = toJSON(serverOpts)) :
Here's my session info, let me know what else I can do to help!
> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] animint_2015.05.11 proto_0.3-10 ggplot2_1.0.0.99
loaded via a namespace (and not attached):
[1] bitops_1.0-6 caTools_1.17.1 colorspace_1.2-4 digest_0.6.8
[5] grid_3.1.3 gtable_0.1.2 MASS_7.3-39 munsell_0.4.2
[9] plyr_1.8.1 Rcpp_0.11.5 RCurl_1.95-4.5 reshape2_1.4.1
[13] RJSONIO_1.3-0 RSelenium_1.3.5 scales_0.2.4 stringr_0.6.2
[17] tools_3.1.3 XML_3.98-1.1
make_tallrect
uses brackets to select the appropriate column from a data.frame. However, the tbl_df
class of dplyr
appears not to permit this.
dat <- iris %>% tbl_df()
x <- dat[, "Sepal.Length"]
class(x)
[1] "tbl_df" "data.frame"
x
Source: local data frame [150 x 1]
Sepal.Length
1 5.1
2 4.9
3 4.7
4 4.6
5 5.0
6 5.4
7 4.6
8 5.0
9 4.4
10 4.9
... ...
So make_tallrect
is stopped when running stopifnot(is.numeric(x))
make_tallrect(dat, "Sepal.Length")
Error: is.numeric(x) is not TRUE
On Firefox 37.0 on mac, I don't see any geom_segment (geom4_segment_summary) in plot 2 nor geom_line in plot 3 (geom6_line_TimeSeries) in http://bl.ocks.org/tdhock/raw/ccd2c65933631f454c09/
Looking in the DOM after executing the JS renderer reveals <line>
and <path>
elements, but the problem seems to be that they have style="stroke-dasharray: 0"
which ends up hiding them. For example changing the value of stroke-dasharray to 1 results in dotted lines, and deleting the stroke-dasharray style results in a solid line.
Is this a bug in the compiler or the renderer? Why is only firefox on Mac affected?
Here is the output:
> library(animint)
Loading required package: ggplot2
Find out what's changed in ggplot2 with
news(Version == "1.0.1", package = "ggplot2")
Loading required package: proto
> example(animint)
animnt> ## Make a Gapminder plot (aka Google motion chart), which is actually
animnt> ## just a scatterplot with size and color that moves over time.
animnt> library(animint)
animnt> data(WorldBank)
animnt> gapminder <-
animnt+ list(ts=ggplot()+
animnt+ make_tallrect(WorldBank, "year")+
animnt+ geom_line(aes(year, life.expectancy, group=country, color=region,
animnt+ clickSelects=country),
animnt+ data=WorldBank, size=4, alpha=3/5),
animnt+ time=list(variable="year",ms=3000),
animnt+ duration=list(year=1000),
animnt+ scatter=ggplot()+
animnt+ geom_point(aes(fertility.rate, life.expectancy, clickSelects=country,
animnt+ showSelected=year, colour=region, size=population),
animnt+ data=WorldBank)+
animnt+ geom_text(aes(fertility.rate, life.expectancy, label=country,
animnt+ showSelected=country, showSelected2=year),
animnt+ data=WorldBank)+
animnt+ make_text(WorldBank, 5, 80, "year")+
animnt+ scale_size_animint(pixel.range=c(2,20), breaks=10^(4:9)))
animnt> animint2dir(gapminder, "WorldBank-viz")
opening a web browser with a file:// URL; if the web page is blank, try running
if (!requireNamespace("servr")) install.packages("servr")
servr::httd("C:/Users/junior/Documents/WorldBank-viz")
Error in shell.exec(url) : 'WorldBank-viz/index.html' not found
Hi, there
Recently I happened to encounter the messy code when I visualize my data including some Chinese characters by means of animint package. The data and code are below.
library( animint )
time <- 1:20
count <- 3:22 + rnorm(20)
count_all <- 201:220 + rnorm(20)
name <- rep("张三", 20)
data <- cbind(time, count, count_all, name)
time <- 1:20
count <- 6:25 + rnorm(20)
count_all <- 300:319 + rnorm(20)
name <- rep("李四", 20)
data <- rbind( data, cbind(time, count, count_all, name) )
data <- data.frame(data)
data$time <- as.numeric(data$time)
data$count <- as.numeric(data$count)
data$count_all <- as.numeric(data$count_all)
viz <-
list(
ts = ggplot() +
make_tallrect( data, "time" ) +
geom_line( aes(time, count, group = name, colour = name,
clickSelects = name),
data = data, size = 3, alpha = 0.8 ),
time = list( variable="time",ms = 3000 ),
duration = list( time = 1000 ),
scatter = ggplot()+
geom_point( aes(count_all, count, clickSelects = name,
showSelected = time, colour = name, size = count_all),
data = data ) +
geom_text( aes(time, count, label = name,
showSelected = name, showSelected2 = time),
data=data ) +
make_text( data, 80, 90, "time" ) +
continuous_scale("size","area",palette = function(x){
scales:::rescale(sqrt(abs(x)), c(1,15), c(0,1))
}) +
xlim(0, 50)
)
animint2dir( viz )
I look forward to your reply.
Many Thanks;
Fang Xie.
I made a viz with geom_step (whose conversion uses ddply) and I got this error
Error in saveLayer(L, df, meta) : could not find function "ddply"
Calls: animint2dir -> parsePlot -> saveLayer
When doing my tests for the animint package, I tried to share an animint visualization online. It works fine when I run it on my computer using animint2dir
and servr::httd
.
However, when I tried to upload it using animint2gist
the plot it generated was completely blank. The code I used to generate this is located here.
Here's my sessionInfo
if that helps
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] animint_2015.01.27 proto_0.3-10 ggplot2_1.0.0.99 dplyr_0.4.1
loaded via a namespace (and not attached):
[1] assertthat_0.1 bitops_1.0-6 caTools_1.17.1 colorspace_1.2-4
[5] DBI_0.3.1 digest_0.6.8 evaluate_0.5.5 formatR_1.0
[9] gistr_0.1.2.9999 grid_3.1.3 gtable_0.1.2 htmltools_0.2.6
[13] httpuv_1.3.2 httr_0.6.1 jsonlite_0.9.14 knitr_1.9
[17] labeling_0.3 lazyeval_0.1.10 magrittr_1.5 MASS_7.3-39
[21] munsell_0.4.2 parallel_3.1.3 plyr_1.8.1 R6_2.0.1
[25] Rcpp_0.11.4 RCurl_1.95-4.5 reshape2_1.4.1 RJSONIO_1.3-0
[29] rmarkdown_0.5.1 RSelenium_1.3.5 scales_0.2.4 servr_0.1
[33] stringr_0.6.2 tools_3.1.3 XML_3.98-1.1
I have three questions and the sample code is based on your example of worldPop.
data(worldPop)
popPlots <-list(bars=ggplot()+geom_bar(aes(x=subcontinent, y=population, clickSelects=subcontinent,fill=subcontinent,alpha=.5), data=worldPop, stat="identity", position="identity")+coord_flip(),
lines=ggplot()+ geom_point(aes(year, population, colour=type), data=worldPop, size=4, alpha=1/4)+ geom_line(aes(year, population, group=subcontinent, clickSelects=subcontinent), data=worldPop, size=4, alpha=3/4))
gg2animint(popPlots)
This is a slightly modified tweak to your sample code.
3 questions-
How do I take the legend of the “bars” plot out? Adding theme(legend.position=”null”) didn’t work
How do I take the x-axis labels out (the names of subcontinents can be known by just clicking on any of the bars, so they can be redundant)? Since the theme deal didn’t work in (1), theme(axis.text.y = element_blank()) didn’t work here as well.
How can I get the selected point/bar to show a bunch of characteristics? For now, it is showing the subcontinent name only, what if I wanted it to show the name and the population number in the bars graph and subcontinent name only on the scatter plot… what if I wanted the subcontinent name, the population, and year in the scatter plot or some additional characteristic as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.