Is there an easy way to get a binary vector of a number? I would like to specify the number of bits to use.
So, for example, 4 in 4bit would return c(F,T,F,F) or in 6bit c(F,F,F,T,F,F).
So what I want to create is something like this but with about 8 factors (tx)
library(ggplot2)
tx <- factor(c("a", "b", "c"))
ty <- rep(0:(2 ^ length(tx) - 1), each=length(tx))
df <- data.frame(x=tx, y=ty)
df$z <- c(F,F,F,F,F,T,F,T,F,F,T,T,T,F,F,T,F,T,T,T,F,T,T,T)
ggplot(df, aes(x, y, fill = z)) + geom_raster()
Could anybody help me with this?