x<-c(0.8,1.8,2.8) y<-c(0.8,1.8,2.8) z<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9) nx<-sprintf("x%s",x) ny<-sprintf("y%s",y) nz<-sprintf("z%s",z)
v<-c( 0.3, 0.2, 0.1, 0, 0, 0, 0, 0, 0, 0.3, 0.2, 0.1, 0.2, 0.3, 0.4, 0.4, 0.5, 0.5, 0.3, 0.4, 0.5, 0.5, 0.6, 0.6, 0.6, 0.7, 0.7, 0.3, 0.2, 0.2, 0.2, 0.3, 0.2, 0, 0, 0, 0.3, 0.4, 0.3, 0.2, 0.3, 0.5, 0.5, 0.6, 0.6, 0.5, 0.4, 0.5, 0.6, 0.6, 0.7, 0.6, 0.8, 0.8, 0.3, 0.4, 0.4, 0.4, 0.5, 0.5, 0.5, 0.5, 0.5, 0.3, 0.2, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.8, 0.3, 0.5, 0.5, 0.6, 0.7, 0.7, 0.9, 0.8, 0.9) myarray<-array(v, c(length(z), length(y), length(x)), dimnames=list(z,y,x)) odftarget<-as.data.frame.table(myarray) names(odftarget) <- c('z', 'y', 'x', 'v') dftarget <- data.frame( z=as.numeric(as.character(odftarget$z)), y=as.numeric(as.character(odftarget$y)), x=as.numeric(as.character(odftarget$x)), v=odftarget$v ) head(dftarget) k <- 16 # number of contours alpha_min_max <- c(0.2, 0.6) colf <- colorRampPalette(rev(RColorBrewer::brewer.pal(11, "RdBu"))) colf <- colorRampPalette(colpal) # isosurfaces are at here lev <- seq(min(dftarget$v), max(dftarget$v), length.out = k) # inner isosurfaces are more solid, outer ones are more transparent. # So, we can see inner isosurfaces by x-ray vision. alpha <- seq(alpha_min_max[1], alpha_min_max[2], length.out = k) rgl::plot3d(z, y, x, type = "n", aspect = TRUE) # create scene# I am using the array here. misc3d::contour3d(myarray, lev, z, y, x, color = colf(k), alpha = alpha, smooth = 3, engine = "rgl", add = TRUE) rgl::aspect3d(2, 1, 1) It works.Thank you. ------------------------------------------------------------------发件人:dncdd via R-help <r-help@r-project.org>发送时间:2017年4月13日(星期四) 18:07收件人:Ismail SEZEN <sezenism...@gmail.com>抄 送:r-help <r-help@r-project.org>主 题:[R] 回复: how to plot three dimension data to filled contour plot or surface plot in R Ask Question This can be a solution. Thank you. Thanks for your time. ------------------------------------------------------------------发件人:Ismail SEZEN <sezenism...@gmail.com>发送时间:2017年4月13日(星期四) 10:05收件人:dncdd <dn...@aliyun.com>抄 送:r-help <r-help@r-project.org>主 题:Re: [R] how to plot three dimension data to filled contour plot or surface plot in R Ask Question On 12 Apr 2017, at 09:08, dncdd <dn...@aliyun.com> wrote: Sorry, I might make the question complicated. I can use filled.contour() to plot mini data 1(three dimension on flat surface). Now my problem is on mini data 2. Let's unfold the mini data 2. r1dn r2dn tdn fdn x, y, z, v 0.8 0.8 0.1 0.3 0.8 0.8 0.2 0.2 0.8 0.8 0.3 0.1 0.8 0.8 0.4 0 0.8 0.8 0.5 0 0.8 0.8 0.6 0 0.8 0.8 0.7 0 0.8 0.8 0.8 0 0.8 0.8 0.9 0 0.8 1.8 0.1 0.3 0.8 1.8 0.2 0.2 0.8 1.8 0.3 0.1 0.8 1.8 0.4 0.2 0.8 1.8 0.5 0.3 0.8 1.8 0.6 0.4 0.8 1.8 0.7 0.4 0.8 1.8 0.8 0.5 0.8 1.8 0.9 0.5 0.8 2.8 0.1 0.3 0.8 2.8 0.2 0.4 0.8 2.8 0.3 0.5 0.8 2.8 0.4 0.5 0.8 2.8 0.5 0.6 0.8 2.8 0.6 0.6 0.8 2.8 0.7 0.6 0.8 2.8 0.8 0.7 0.8 2.8 0.9 0.7 1.8 0.8 0.1 0.3 1.8 0.8 0.2 0.2 1.8 0.8 0.3 0.2 1.8 0.8 0.4 0.2 1.8 0.8 0.5 0.3 1.8 0.8 0.6 0.2 1.8 0.8 0.7 0 1.8 0.8 0.8 0 1.8 0.8 0.9 0 1.8 1.8 0.1 0.3 1.8 1.8 0.2 0.4 1.8 1.8 0.3 0.3 1.8 1.8 0.4 0.2 1.8 1.8 0.5 0.3 1.8 1.8 0.6 0.5 1.8 1.8 0.7 0.5 1.8 1.8 0.8 0.6 1.8 1.8 0.9 0.6 1.8 2.8 0.1 0.5 1.8 2.8 0.2 0.4 1.8 2.8 0.3 0.5 1.8 2.8 0.4 0.6 1.8 2.8 0.5 0.6 1.8 2.8 0.6 0.7 1.8 2.8 0.7 0.6 1.8 2.8 0.8 0.8 1.8 2.8 0.9 0.8 2.8 0.8 0.1 0.3 2.8 0.8 0.2 0.4 2.8 0.8 0.3 0.4 2.8 0.8 0.4 0.4 2.8 0.8 0.5 0.5 2.8 0.8 0.6 0.5 2.8 0.8 0.7 0.5 2.8 0.8 0.8 0.5 2.8 0.8 0.9 0.5 2.8 1.8 0.1 0.3 2.8 1.8 0.2 0.2 2.8 1.8 0.3 0.4 2.8 1.8 0.4 0.5 2.8 1.8 0.5 0.5 2.8 1.8 0.6 0.6 2.8 1.8 0.7 0.6 2.8 1.8 0.8 0.7 2.8 1.8 0.9 0.8 2.8 2.8 0.1 0.3 2.8 2.8 0.2 0.5 2.8 2.8 0.3 0.5 2.8 2.8 0.4 0.6 2.8 2.8 0.5 0.7 2.8 2.8 0.6 0.7 2.8 2.8 0.7 0.9 2.8 2.8 0.8 0.8 2.8 2.8 0.9 0.9 When x is 0.8, y is 0.8, z is 0.1, then v is 0.3. So v is not limited by a function like v ~ f(x,y,z). I mean x,y,z is just like labels on the 3d space.You have give me many suggestions. I think that maybe scatterplot with colors on v on 3d space is a solution. I will try it later. At the beginning, I was wondering a 3d surface plot or 3d filled.contour on 3d space. I am not sure whether it is possble. First of all, v is function of x,y,z according to sample above wheter you accept or not. Because x,y,z represents coordinates of v in the 3D space and if someone wants to plot contours between those points, he/she needs a v(x,y,z) function that can calculate values (v) between x,y,z coordinates. Let’s get back to main question. I think you want something like as [1] and [2]. Your best shot is misc3d package. I created a simple example how to plot isosurfaces and you can find different strategies to plot 4D data in 3D space at [3]. #——————————library(misc3d)# let's create a function to create a sample data to visualizef <- function(x, y, z) sin(x) * sin(y) * sin(z)x <- z <- seq(0, pi, length.out = 15)y <- seq(-pi, pi, length.out = 15)d <- expand.grid(x, y, z)colnames(d) <- c("x", "y", "z")d$v <- with(d, f(x, y, z)) # this is your initial datahead(d) k <- 16 # number of contoursalpha_min_max <- c(0.2, 0.6)colf <- colorRampPalette(rev(RColorBrewer::brewer.pal(11, "RdBu"))) # isosurfaces are at herelev <- seq(min(d$v), max(d$v), length.out = k)# inner isosurfaces are more solid, outer ones are more transparent.# So, we can see inner isosurfaces by x-ray vision.alpha <- seq(alpha_min_max[1], alpha_min_max[2], length.out = k) rgl::plot3d(x, y, z, type = "n", aspect = TRUE) # create scenemisc3d::contour3d(f, lev, x, y, z, color = colf(k), alpha = alpha, smooth = 3, engine = "rgl", add = TRUE)rgl::aspect3d(1, 2, 1) # set aspect, y is different from x and z.#—————————— 1- http://stackoverflow.com/a/11319175/5578842- http://mathematica.stackexchange.com/a/198193- https://www.jstatsoft.org/article/view/v028i01 [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.