r - Reformatting data in order to plot 2D continuous heatmap -
i have data stored in data.frame
plot continuous heat map. have tried using interp
function akima
package, data can large (2 million rows) avoid if possible takes long time. here format of data
l1 <- c(1,2,3) grid1 <- expand.grid(l1, l1) lprobdens <- c(0,2,4,2,8,10,4,8,2) df <- cbind(grid1, lprobdens) colnames(df) <- c("age1", "age2", "probdens") age1 age2 probdens 1 1 0 2 1 2 3 1 4 1 2 2 2 2 8 3 2 10 1 3 4 2 3 8 3 3 2
i format in length(df$age1) x length(df$age2)
matrix. gather once formatted in manner able use basic functions such image
plot 2d histogram continuous heat map similar created using akima
package. here how think transformed data should look. please correct me if wrong.
1 2 3 1 0 2 4 2 2 8 8 3 4 10 2
it seems though ldply
can't seem sort out how works.
i forgot mention, $age information continuous , regular, such list age1 equal age2 age1 >= age2. guess means may classed continuous data stands , doesn't require interp
function.
ok think want. matter of reshaping data reshape
s 'cast function. value.var
argument avoid warning message r tried guess value use. result not change if omit it.
library(reshape2) as.matrix(dcast(dat, age1 ~ age2, value.var = "probdens")[-1]) 1 2 3 [1,] 0 2 4 [2,] 2 8 8 [3,] 4 10 2
Comments
Post a Comment