r - How to plot a contour/ heat map plot with 3 vectors? -


here toy version of problem

x = runif(10); y = runif(10); z = (x+y)*(x-y); 

i generate heatmap of z vs. (x+y) , (x-y). problem z vector , not defined on combinations of y , x. please note not looking answer generates z these missing values, not possibility in real version of problem. minimal version work with. solutions i've been able find, such filled.contour need matrix z specified on grid of independent variables rather set of (x,y,z) data points no structure per se.

package akima has need. bivariate interpolation interp. generate z values missing combinations, couldnt exclude if wanted to? if aren't generating z-values plot 3d scatter of z ~ x*y.

x = runif(10); y = runif(10); z = (x+y)*(x-y);  library(akima) dens <- interp(x+y, x-y, z,                 xo=seq(min(x+y), max(x+y), length=100),                yo=seq(min(x-y), max(x-y), length=100),                duplicate="median")  filled.contour(dens, xlab="x+y", ylab="x-y", main="z",                color.palette = heat.colors) 

enter image description here

if set on not interpolating, add ggplot options provided @frank, there number of aesthetics can use contrast points third dimension.

library(ggplot2) dat <- data.frame(x1=x+y, x2=x-y, z=z)  ## scaling points z dimension using size, color, , shading ggplot(dat, aes(x1, x2, size=z, alpha=z, color=z)) +   geom_point() +   scale_color_gradient(low="red", high="yellow") +   theme_bw() 

enter image description here


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -