Two pending features to metricsgraphics
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I’ve been slowly prodding the metricsgraphics package towards a 1.0.0 release, but there are some rough edges that still need sorting out. One of them is the ability to handle passing in variables for the x
& y
accessor values (you can pass in bare and quoted strings). This can now be achieved (in the dev01
branch) via mjs_plot_
and in mjs_plot
proper in the github main branch thanks to a PR by Jonathan Owen. If everything stays stable with the PR, I’ll just fold the code into mjs_plot
for the 0.9.0
CRAN release.
One other pending feature is the ability to turn basic (single geom_
) ggplot
objects into metricsgraphics
plots. Sometimes it’s just easier/nicer to “think” in ggplot
and it may be the case that one might have coded a quick histogram/scatter/line plot in ggplot
and want an equally quick interactive version. This can also now be achieved (again, in beta) via as_mjsplot
. While the previous addition is fairly self-explanatory, this new one needs a few examples. Please note that the package installation is coming from the dev01
branch:
devtools::install_github("hrbrmstr/metricsgraphics", ref="dev01") library(metricsgraphics) library(ggplot2) dat <- data.frame(year=seq(1790, 1970, 10), uspop=as.numeric(uspop)) set.seed(5689) movies <- movies[sample(nrow(movies), 1000), ] gg1 <- ggplot(dat, aes(x=year, y=uspop)) + geom_line() gg2 <- ggplot(dat, aes(x=year, y=uspop)) + geom_point() gg3 <- ggplot(movies, aes(rating)) + geom_histogram() gg4 <- ggplot(movies, aes(rating)) + geom_histogram(binwidth = 0.1) gg1 as_mjsplot(gg1) gg2 as_mjsplot(gg2) gg3 as_mjsplot(gg3) gg4 as_mjsplot(gg4) |
Which you can see below:
As you can see, as_mjsplot
will do it’s best to figure out the bins (if using geom_histogram
) and also axis labels. Support for converting geom_vline
and geom_hline
to markers and baselines (respectively) is a work in progress.
I’ve only done limited testing with some basic single geom_
constructs, but if there are any bugs with it or feature requests (remember, the MetricsGraphics.js library has a very limited repertoire) please post an issue on GitHub tagging the dev01
branch.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.