Re: [R] create a '3D line plot'

2010-09-13 Thread Jim Lemon

On 09/13/2010 06:17 AM, Karl Brand wrote:

Cheers!

All excellent, runable examples helping me progress quickly.

Being more a qualitative plot, the y-axis is less important. But it did
get me thinking-

Coloring each of the plotted lines, say 'altitude colors' like the
classic volcano example to reflect the (scaled) values the lines
represent might be effective at representing individual y-axis magnitude
for each line. Perhaps gray background at least.

Maybe if there were examples of the lines() func. using colors dependent
on the y-value? Or some one already made a function for achieving this?
(Google didnt return anything obvious for me...yet).


Hi Karl,
Have a look at the clplot and color.scale.lines functions in the plotrix 
package.


Jim

__
R-help@r-project.org mailing list
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.


[R] create a '3D line plot'

2010-09-12 Thread Karl Brand

Esteemed useRs and developeRs,

I need to create a  '3D line plot' (proper name?) of which an excellent 
example can be viewed here:


http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg

I have some experience using the rgl package to create 3D PCA plots, but 
have no idea where to start for an image like this.


I'd really appreciate suggestions  help on how might achieve this using R,

Karl

--
Karl Brand
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268

__
R-help@r-project.org mailing list
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.


Re: [R] create a '3D line plot'

2010-09-12 Thread Duncan Murdoch

On 12/09/2010 10:12 AM, Karl Brand wrote:

Esteemed useRs and developeRs,

I need to create a  '3D line plot' (proper name?) of which an excellent 
example can be viewed here:


http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg

I have some experience using the rgl package to create 3D PCA plots, but 
have no idea where to start for an image like this.


I'd really appreciate suggestions  help on how might achieve this using R,


I wouldn't use rgl for that:  it's really a flat 2D plot, without 
perspective, shading or anything else that 3D plots have other than 
foreground objects hiding background ones.  You can draw it by using 
polygon() to hide the background then lines() to draw the lines.


Here's an example using regular 2d graphics:


n - 60
m - 50
x - seq(-4,4, len=m)

# Make up some fake y data

y - matrix(NA, n, m)
for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1)

par(bg=black)
yrange - range(c(y, y+n/20))

plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange)

for (i in n:1) {
  y1 - c(y[i,] + i/20, 0, 0)
  x1 - c(x, x[m], x[1])
  polygon(x1,y1,col=black)

  lines(x, y[i,] + i/20, col=white)

}

The problem with this kind of plot is that it's almost impossible to 
display a usable vertical scale.


Duncan Murdoch

__
R-help@r-project.org mailing list
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.


Re: [R] create a '3D line plot'

2010-09-12 Thread David Winsemius


On Sep 12, 2010, at 10:12 AM, Karl Brand wrote:


Esteemed useRs and developeRs,

I need to create a  '3D line plot' (proper name?) of which an  
excellent example can be viewed here:


http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg


Set up blank plot region with proper ranges for x and ylim that could  
be say 0:60 with the intent of scaling your 50 individual y ranges to  
0-10

Scale your y values to be within 0-10
Fill plot area black:
Draw from top down using polygon with white lines at cex=2 and black  
fill.

Then something along these lines:
for(ilevel in 0:50){ polygon(x,yscaled+50-ilevel, col=black,  
border=white, lwd=2)}


#--- tested code
opar - par(bg=black)
 set.seed(1)
 Ldens - vector(mode=list, 50)
 for(i in 1:50) {
   Ldens[[i]] - density(rnorm(100), from=-3,to=3)
  with(Ldens[[i]], polygon(x=c(x[c(1, 1:512, 512)]), y= c(0, 50-i 
+20*y[1:512], 0),

   col=black, border=white))
 }
par(opar)
#-


Got any data?

--
David.




I have some experience using the rgl package to create 3D PCA plots,  
but have no idea where to start for an image like this.


I'd really appreciate suggestions  help on how might achieve this  
using R,


Karl

--
Karl Brand

--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
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.


Re: [R] create a '3D line plot'

2010-09-12 Thread Dennis Murphy
Hi:

Another approach is to use lattice:

http://lmdvr.r-forge.r-project.org/figures/figures.html

Go to Chapter 14 and click on Figure 14.3; the code is on the RHS of the
figure.

HTH,
Dennis

On Sun, Sep 12, 2010 at 7:12 AM, Karl Brand k.br...@erasmusmc.nl wrote:

 Esteemed useRs and developeRs,

 I need to create a  '3D line plot' (proper name?) of which an excellent
 example can be viewed here:

 http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg

 I have some experience using the rgl package to create 3D PCA plots, but
 have no idea where to start for an image like this.

 I'd really appreciate suggestions  help on how might achieve this using R,

 Karl

 --
 Karl Brand
 Department of Genetics
 Erasmus MC
 Dr Molewaterplein 50
 3015 GE Rotterdam
 T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268

 __
 R-help@r-project.org mailing list
 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
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.


Re: [R] create a '3D line plot'

2010-09-12 Thread Karl Brand

Cheers!

All excellent, runable examples helping me progress quickly.

Being more a qualitative plot, the y-axis is less important. But it did 
get me thinking-


Coloring each of the plotted lines, say 'altitude colors' like the 
classic volcano example to reflect the (scaled) values the lines 
represent might be effective at representing individual y-axis magnitude 
for each line. Perhaps gray background at least.


Maybe if there were examples of the lines() func. using colors dependent 
on the y-value? Or some one already made a function for achieving this? 
(Google didnt return anything obvious for me...yet).


Sincere thanks for help thus far, and welcome any further pointers,

Karl


On 9/12/2010 4:50 PM, Duncan Murdoch wrote:

On 12/09/2010 10:12 AM, Karl Brand wrote:

Esteemed useRs and developeRs,

I need to create a '3D line plot' (proper name?) of which an excellent
example can be viewed here:

http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg

I have some experience using the rgl package to create 3D PCA plots,
but have no idea where to start for an image like this.

I'd really appreciate suggestions  help on how might achieve this
using R,


I wouldn't use rgl for that: it's really a flat 2D plot, without
perspective, shading or anything else that 3D plots have other than
foreground objects hiding background ones. You can draw it by using
polygon() to hide the background then lines() to draw the lines.

Here's an example using regular 2d graphics:


n - 60
m - 50
x - seq(-4,4, len=m)

# Make up some fake y data

y - matrix(NA, n, m)
for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1)

par(bg=black)
yrange - range(c(y, y+n/20))

plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange)

for (i in n:1) {
y1 - c(y[i,] + i/20, 0, 0)
x1 - c(x, x[m], x[1])
polygon(x1,y1,col=black)

lines(x, y[i,] + i/20, col=white)

}

The problem with this kind of plot is that it's almost impossible to
display a usable vertical scale.

Duncan Murdoch


--
Karl Brand
Department of Genetics
Erasmus MC
Dr Molewaterplein 50
3015 GE Rotterdam
T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268

__
R-help@r-project.org mailing list
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.


Re: [R] create a '3D line plot'

2010-09-12 Thread Dennis Murphy
Hi:

Here's a fairly basic ggplot2 version with a few warts in it:

# Generate means
means - rpois(30, 10)
# Create 30 Gaussian random samples of size 100, using means to
# define the population mean for each sample (via sapply)
df - data.frame(ds = rep(1:30, each = 100),
  x = as.vector(sapply(means, function(x) rnorm(100, means[x]))) )

library(ggplot2)

# Two versions of density plot:
# Version 1: no fill color, just curves
h - ggplot(df2, aes(x = x, colour = ds))
h + geom_density() + facet_grid(ds ~ ., as.table = FALSE) +
 opts(axis.text.y = theme_blank())

# as.table = FALSE allows you to read upward from data set 1 to 30

# Version 2: add fill color
g - ggplot(df2, aes(x = x, colour = ds, fill = ds))
g + geom_density() + facet_grid(ds ~ ., as.table = FALSE) +
 opts(axis.text.y = theme_blank())

Some problems that arose:
(1) I couldn't figure out how to set a range of colors beyond the
default. I tried several things with scale_colour_*, but one
problem or another arose. Ideally, I'd like to be able to set
the color by mean value, but that would require some thinking
(OMG!) Some features of scales are still a bit beyond me...
(2) I could get rid of the y-axis tick labels, but couldn't get
rid of both the labels and the ticks. I was also hoping to use
theme_bw() using just the horizontal grid lines, but no. I just
thought of a couple ideas to play with on that front., though,
so I'll continue to toy with it for a bit.

All in all, for a few lines of code, it's a pretty decent plot, even
though it needs some work. Thank Hadley for that...

HTH,
Dennis

On Sun, Sep 12, 2010 at 1:17 PM, Karl Brand k.br...@erasmusmc.nl wrote:

 Cheers!

 All excellent, runable examples helping me progress quickly.

 Being more a qualitative plot, the y-axis is less important. But it did get
 me thinking-

 Coloring each of the plotted lines, say 'altitude colors' like the classic
 volcano example to reflect the (scaled) values the lines represent might be
 effective at representing individual y-axis magnitude for each line. Perhaps
 gray background at least.

 Maybe if there were examples of the lines() func. using colors dependent on
 the y-value? Or some one already made a function for achieving this? (Google
 didnt return anything obvious for me...yet).

 Sincere thanks for help thus far, and welcome any further pointers,

 Karl



 On 9/12/2010 4:50 PM, Duncan Murdoch wrote:

 On 12/09/2010 10:12 AM, Karl Brand wrote:

 Esteemed useRs and developeRs,

 I need to create a '3D line plot' (proper name?) of which an excellent
 example can be viewed here:

 http://cococubed.asu.edu/images/87a/images/unknown_pleasures.jpg

 I have some experience using the rgl package to create 3D PCA plots,
 but have no idea where to start for an image like this.

 I'd really appreciate suggestions  help on how might achieve this
 using R,


 I wouldn't use rgl for that: it's really a flat 2D plot, without
 perspective, shading or anything else that 3D plots have other than
 foreground objects hiding background ones. You can draw it by using
 polygon() to hide the background then lines() to draw the lines.

 Here's an example using regular 2d graphics:


 n - 60
 m - 50
 x - seq(-4,4, len=m)

 # Make up some fake y data

 y - matrix(NA, n, m)
 for (i in 1:n) y[i,] - dnorm(x)*runif(m, 0.5,1)

 par(bg=black)
 yrange - range(c(y, y+n/20))

 plot(x, x, type=n, axes=FALSE, bg=black, ylim=yrange)

 for (i in n:1) {
 y1 - c(y[i,] + i/20, 0, 0)
 x1 - c(x, x[m], x[1])
 polygon(x1,y1,col=black)

 lines(x, y[i,] + i/20, col=white)

 }

 The problem with this kind of plot is that it's almost impossible to
 display a usable vertical scale.

 Duncan Murdoch


 --
 Karl Brand
 Department of Genetics
 Erasmus MC
 Dr Molewaterplein 50
 3015 GE Rotterdam
 T +31 (0)10 704 3457 |F +31 (0)10 704 4743 |M +31 (0)642 777 268


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.