An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090331/c7b56c82/attachment-0002.pl>
3d cloud plot with point size reflecting variable value
4 messages · R User R User, Dieter Menne, Deepayan Sarkar
R User R User <ruser2008 <at> googlemail.com> writes:
I'm using the cloud function to plot the iris data as per the document: http://www.stat.ucl.ac.be/ISpersonnel/lecoutre/stats/fichiers/_gallery.pdf I'd like to change the point size to reflect a fourth variable, as done here http://www.cis.hut.fi/projects/somtoolbox/download/pics2/shotvs2_origdata.png Does anybody know how to do this? There doesn't seem to be an option in cloud()
My first idea was to add cex = iris$PetalLength, which failed, taking the first value of cex only. In panel.3dscatter I found the line cex <- rep(cex, length.out = n) Which looks like cex is not vectored. So my approach would be to make a copy of panel.3dscatter and do the correct cex replacement there. I might be wrong, however, Deepayan has the last say. Dieter
On Tue, Mar 31, 2009 at 8:57 AM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
R User R User <ruser2008 <at> googlemail.com> writes:
I'm using the cloud function to plot the iris data as per the document: http://www.stat.ucl.ac.be/ISpersonnel/lecoutre/stats/fichiers/_gallery.pdf I'd like to change the point size to reflect a fourth variable, as done here http://www.cis.hut.fi/projects/somtoolbox/download/pics2/shotvs2_origdata.png Does anybody know how to do this? There doesn't seem to be an option in cloud()
My first idea was to add ?cex = iris$PetalLength, which failed, taking the first value of cex only. In panel.3dscatter I found the line cex <- rep(cex, length.out = n) Which looks like cex is not vectored.
How so? panel.3dscatter() in fact goes to some lengths to be vectorized: 'n' is the number of points being plotted, and 'cex' is replicated to be equally long here. This is needed so that the 'cex' values can later be reordered in the same way as the points being plotted (by decreasing depth). The following should work: cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris, pch = 1, cex = with(iris, 3 * Sepal.Width / max(Sepal.Width))) One caveat is that this will not work in a multi-panel plot. In that case, a custom panel function will need to create a suitable subset of 'cex' (cex[subscripts]) before calling panel.3dscatter(). -Deepayan
So my approach would be to make a copy of panel.3dscatter and do the correct cex replacement there. I might be wrong, however, Deepayan has the last say. Dieter
On Tue, Mar 31, 2009 at 11:49 AM, Deepayan Sarkar
<deepayan.sarkar at gmail.com> wrote:
On Tue, Mar 31, 2009 at 8:57 AM, Dieter Menne <dieter.menne at menne-biomed.de> wrote:
R User R User <ruser2008 <at> googlemail.com> writes:
I'm using the cloud function to plot the iris data as per the document: http://www.stat.ucl.ac.be/ISpersonnel/lecoutre/stats/fichiers/_gallery.pdf I'd like to change the point size to reflect a fourth variable, as done here http://www.cis.hut.fi/projects/somtoolbox/download/pics2/shotvs2_origdata.png Does anybody know how to do this? There doesn't seem to be an option in cloud()
My first idea was to add ?cex = iris$PetalLength, which failed, taking the first value of cex only. In panel.3dscatter I found the line cex <- rep(cex, length.out = n) Which looks like cex is not vectored.
How so? panel.3dscatter() in fact goes to some lengths to be vectorized: 'n' is the number of points being plotted, and 'cex' is replicated to be equally long here. This is needed so that the 'cex' values can later be reordered in the same way as the points being plotted (by decreasing depth). The following should work: cloud(Sepal.Length ~ Petal.Length * Petal.Width, data = iris, pch = 1, cex = with(iris, 3 * Sepal.Width / max(Sepal.Width))) One caveat is that this will not work in a multi-panel plot. In that case, a custom panel function will need to create a suitable subset of 'cex' (cex[subscripts]) before calling panel.3dscatter().
I think I see the problem: this will also not work if there is a
'groups' argument. In general, that will also require a panel
function, but another option is to use vectorized color:
with(iris,
cloud(Petal.Length ~ Sepal.Length * Sepal.Width, pch = 16,
cex = 2 * Petal.Width / max(Petal.Width),
col = c(2, 3, 4)[as.numeric(Species)], aspect = c(0.7, 2)))
-Deepayan