This is the personal R package of David Robinson.
I'm making this public for my own convenience, without any guarantees. Functions are documented, though.
Personal R package
License: Other
This is the personal R package of David Robinson.
I'm making this public for my own convenience, without any guarantees. Functions are documented, though.
Hi David,
Thanks for these, they are great.
I am trying to use reorder_within with facet_grid with two faceting variables. Now it seems like it was not designed for this and I was trying to update the functions to fit. It's easy enough with reorder_within but I cannot quite figure out how to do it with scale_x_reordered().
Example below of why scale_x_reorder needs to be rejigged for it, but I haven't a clue where to start. Any help definitely appreciated.
library(tidyverse)
library(drlib)
#>
#> Attaching package: 'drlib'
#> The following object is masked from 'package:tidyr':
#>
#> expand_grid
library(datasets)
data(iris)
df<-iris%>%
gather(Type, value, -Species)%>%
separate(Type, c("type", "attribute"), sep="[.]")
#using jsut reorder_within to test that it works
df%>%
ggplot(aes(reorder_within(Species, value, type), value, color=type))+
geom_point()+
facet_grid(.~type, scales = "free_x")+
scale_x_reordered()
#creating a new reorder that would work with 2 varaibles
reorder_within_2 <- function(x, by, within, within1, fun = mean, sep = "___", ...) {
new_x <- paste(x, within, within1, sep = sep)
stats::reorder(new_x, by, FUN = fun)
}
#but now, creating the chart below, the species names repeat.
df%>%
ggplot(aes(reorder_within_2(Species, value, type, attribute), value, color=type))+
geom_point()+
facet_grid(attribute~type, scales = "free_x")+
scale_x_reordered()+
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Created on 2020-01-27 by the reprex package (v0.3.0)
Hi David, I love accumulate_while, any chance it could get updated to avoid the error below (the results it produces are still correct).
drlib::accumulate_while(17,~.+1,~.<20)
as_function()
is deprecated; please use as_mapper()
or rlang::as_function()
insteadas_function()
is deprecated; please use as_mapper()
or rlang::as_function()
instead[[1]]
[1] 17
[[2]]
[1] 18
[[3]]
[1] 19
[[4]]
[1] 20
Another request: could you create accumulate_while_*, where * = lgl, int, dbl, chr, etc., so in the example above i would have used
drlib::accumulate_while_int(17L,~.+1L,~.<20L)
[1] 17 18 19 20
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.