Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is an example in ?plot3d if you are talking about plotting points in a 3d space and colouring them:</p> <pre><code>x &lt;- sort(rnorm(1000)) y &lt;- rnorm(1000) z &lt;- rnorm(1000) + atan2(x,y) plot3d(x, y, z, col=rainbow(1000)) </code></pre> <p>But if you mean to colour the points by a 4th variable, say a grouping variable, then we can modify the example above to do this by creating a grouping variable</p> <pre><code>grp &lt;- gl(5, 200) ## 5 groups 200 members each ## now select the colours we want cols &lt;- 1:5 ## Now plot plot3d(x, y, z, col=cols[grp]) </code></pre> <hr> <p>OK, is this more what you want?</p> <pre><code>X &lt;- 1:10 Y &lt;- 1:10 ## Z is now a 100 row object of X,Y combinations Z &lt;- expand.grid(X = X, Y = Y) ## Add in Z1, which is the 3rd variable ## X,Y,Z1 define the surface, which we colour according to ## 4th variable Z2 Z &lt;- within(Z, { Z1 &lt;- 1.2 + (1.4 * X) + (-1.9 * Y) Z2 &lt;- 1.2 + (1.4 * X) - (1.2 * X^2) + (1.9 * Y) + (-1.3 * Y^2) Z3 &lt;- 1.2 + (1.4 * X) + (-1.9 * Y) + (-X^2) + (-Y^2)}) ## show the data head(Z) ## Set-up the rgl device with(Z, plot3d(X, Y, Z1, type = "n")) ## Need a scale for Z2 to display as colours ## Here I choose 10 equally spaced colours from a palette cols &lt;- heat.colors(10) ## Break Z2 into 10 equal regions cuts &lt;- with(Z, cut(Z2, breaks = 10)) ## Add in the surface, colouring by Z2 with(Z, surface3d(1:10,1:10, matrix(Z1, ncol = 10), color = cols[cuts], back = "fill")) with(Z, points3d(X, Y, Z1, size = 5)) ## show grid X,Y,Z1 </code></pre> <p>Here's a modification where the plane surface <code>Z1</code> is curved (<code>Z3</code>).</p> <pre><code>## Set-up the rgl device plotting Z3, a curved surface with(Z, plot3d(X, Y, Z3, type = "n")) with(Z, surface3d(1:10,1:10, matrix(Z3, ncol = 10), color = cols[cuts], back = "fill")) </code></pre> <p>The detail of what I did to get <code>Z2</code> probably doesn't matter, but I tried to get something like the graph you linked to.</p> <p>If I've still not got what you want, can you edit your Q with some example data and give us a better idea of what you want?</p> <p>HTH</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload