plot - Plotting Probability Density Heatmap Over Time in R -
let's have output of monte-carlo simulation of 1 variable on several different iterations (think millions). each iteration, have values of variable @ each point in time (ranging t=1 t=365).
i produce following plot: each point in time, t, on x axis , each possible value "y" in given range, set color of x,y "k" "k" count of how many observations within vicinity of distance "d" x,y.
i know can make density heatmaps 1d data, there package doing on 2 dimensions? have use kriging?
edit: data structure matrix.
data matrix day number [,1] [,2] [,3] [,4] [,5] ... [,365] iteration [1,] 0.000213 0.001218 0.000151 0.000108 ... 0.000101 [2,] 0.000314 0.000281 0.000117 0.000103 ... 0.000305 [3,] 0.000314 0.000281 0.000117 0.000103 ... 0.000305 [4,] 0.000171 0.000155 0.000141 0.000219 ... 0.000201 . . . [100000000,] 0.000141 0.000148 0.000144 0.000226 ... 0.000188
i want to, each "day" have pixels running vertically across "day" represent probability density of iteration's values day in color. result should heatmap.
here 1 solution think after.
generate data.
mydata <- mapply(rnorm, 1000, 200, mean=seq(-50,50,0.5))
this matrix 1000 rows (observations) , 201 time points. in each time point mean of data there shifts gradually -50 50. 0.5 each time.
get densities.
mydensities <- apply(mydata, 2, density, from=-500, to=500)
this give list of densities each column. in order them plottable side side specified ranges (from -500 500) manually.
obtain density values list.
ys <- sapply(mydensities, "[", "y")
this again list. need matrix that.
get matrix list.
img <- do.call(cbind, ys)
this combines ys
elements column.
plot.
filled.contour(x=1:ncol(img), y=mydensities[[1]]$x, t(img))
i use filled.contour that. can around other 2-d plot functions. used values obtained densities d[[1]]$x
.
and here result:
the shift -50 50 visible.
not sure if can work millions of time points. plotting million makes little sense since in case limited number of pixels. kind of pre-processing might necessary.
Comments
Post a Comment