Re: [R] It This data viz possible in R?

2010-04-08 Thread baptiste auguie
An improved version below (now the connections are drawn in the correct order),

library(grid)

arcTextGrob - function(x=unit(0.5, npc), y=unit(0.5, npc),
labels=library()$results[,1],
links=sample(seq_along(labels), 20, rep=T),
default.units=npc,
gp=gpar(), ...)
  {

## circle
full.height - sum(stringHeight(labels))
radius - 1.2 /(2*pi) * full.height
g1 - circleGrob(0.5, 0.5, r=radius, default.units=npc, gp=gpar(col=NA))

## text labels
n - length(labels)
ang - seq(0, n-1) * 2 * pi/n

radius.npc - convertUnit(radius, npc, val=T)
coords - data.frame(x=0.5+radius.npc*cos(ang), y=0.5+radius.npc*sin(ang))
g2 - textGrob(labels, x=coords$x , y=coords$y , rot=ang*180/pi,
default.units=npc, hjust=0)

## connecting pairs

xm - matrix(coords$x[links], ncol=2, byrow=T)
ym - matrix(coords$y[links], ncol=2, byrow=T)

## find out which pairs are not in trigo order
## and swap them
swap - as.logical(sign((xm[, 1]-0.5)*(ym[, 2]-0.5) - (xm[,
2]-0.5)*(ym[, 1]-0.5)) + 1)
xm[swap, ] - rev(xm[swap])
ym[swap, ] - rev(ym[swap])

g3 - do.call(gList, mapply(curveGrob, x1=xm[, 1], y1=ym[, 1],
x2=xm[, 2], y2=ym[, 2],
ncp=8, curvature=0.4, square=F, SIMPLIFY=FALSE))

gTree(children=gList(g1, g2, g3),
  outer.radius=convertUnit(radius, npc) +
  convertUnit(max(stringWidth(labels)), npc))
  }


grid.arcText - function(...)
  grid.draw(arcTextGrob(...))

set.seed(1234)
grid.newpage()
grid.arcText()


On 7 April 2010 23:13, baptiste auguie baptiste.aug...@googlemail.com wrote:
 The following grob might be a starting point. I couldn't find a clean
 way of orienting the linking arcs though...

 Best,

 baptiste

 library(grid)

 paragraph - Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 Praesent adipiscing lobortis placerat. Nunc vel arcu mauris. Aliquam
 erat volutpat. Integer et pharetra orci. Sed rutrum facilisis dolor et
 condimentum. Class aptent taciti sociosqu ad litora torquent per
 conubia nostra, per inceptos himenaeos. Nunc leo nibh, pellentesque et
 convallis quis, mattis ut mi. Nunc dignissim auctor elit pulvinar
 malesuada. Cras dapibus hendrerit ligula quis suscipit. Proin porta
 tempor feugiat. Ut quis nisi lacus, et egestas tortor. Fusce porttitor
 tincidunt fringilla. Vivamus rhoncus ultrices elit, at fermentum nisl
 scelerisque et. Duis placerat est at justo vestibulum sodales.
 Curabitur quis eros tellus. 

 words - strsplit(paragraph,  )[[1]]
 labels - apply(matrix(words, ncol=3, byrow=T), 1, paste, collapse= )

 arcTextGrob - function(x=unit(0.5, npc), y=unit(0.5, npc),
                        labels=letters[1:10],
                        links=sample(seq_along(labels), 10),
                        min.radius=unit(2, cm),
                        default.units=npc,
                        gp=gpar(), ...)
  {

    ##     circle of perimeter = 1.5 * the text height
    full.height - sum(stringHeight(labels))
    radius - 1.5 /(2*pi) * full.height

    g1 - circleGrob(0.5, 0.5, r=radius, default.units=npc)

    ##     text labels
    n - length(labels)
    ang - seq(0, n-1) * 2 * pi/n

    radius.mm - convertUnit(radius, npc, val=T)
    coords - data.frame(x=0.5+radius.mm*cos(ang), y=0.5+radius.mm*sin(ang))
    g2 - textGrob(labels, x=coords$x , y=coords$y , rot=ang*180/pi,
 default.units=npc, hjust=0)

    ## links,
    ## NOTE: they are not well ordered...

    xm - matrix(coords$x[links], ncol=2, byrow=T)
    ym - matrix(coords$y[links], ncol=2, byrow=T)

    g3 - do.call(gList, mapply(curveGrob, x1=xm[, 1], y1=ym[, 1],
 x2=xm[, 2], y2=ym[, 2],
                                ncp=8, curvature=0.3, square=F, 
 SIMPLIFY=FALSE))

    gTree(children=gList(g1, g2, g3))
  }


 grid.arcText - function(...)
  grid.draw(arcTextGrob(...))

 dev.new()
 grid.arcText(labels=labels)




 On 7 April 2010 16:44, Gabor Grothendieck ggrothendi...@gmail.com wrote:
 There is draw.arc in the plotrix package.

 On Wed, Apr 7, 2010 at 10:20 AM, baptiste auguie
 baptiste.aug...@googlemail.com wrote:
 Hi,

 Barry suggested a way to place the text labels; I would like to point
 out the grid.curve() function that might help in connecting the labels
 with nice-looking curves. I don't know of a base graphics equivalent
 (xspline() might come close) so it might be best to opt for Grid.

 HTH,

 baptiste


 On 7 April 2010 15:46, Barry Rowlingson b.rowling...@lancaster.ac.uk 
 wrote:
 On Wed, Apr 7, 2010 at 2:28 PM, Brock Tibert btibe...@yahoo.com wrote:
 Hi All,

 I am new to R, but it has been a lot of fun learning as I go and have 
 been blow away by what it can do.  Came across this example and wanted to 
 see if ggplot2 or some other visualization package could make this sort 
 of graphic.

 

Re: [R] It This data viz possible in R?

2010-04-08 Thread Jim Lemon

On 04/08/2010 12:44 AM, Gabor Grothendieck wrote:

There is draw.arc in the plotrix package.

Well, draw.arc is specified by center, radius and start/finish angles, 
so it would be a lot of calculation to get these from the two points 
that must be joined on the circumference. I would probably translate 
this into the Postscript arct command, as you would probably have to use 
the Postscript or similar device to get a decent image. I programmed 
something similar, but a lot simpler, some years ago in Postscript and 
it worked out pretty well. Getting the correct angle for the text was 
tricky, you can see how some of the text on the example is upside down.


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] It This data viz possible in R?

2010-04-07 Thread Brock Tibert
Hi All,

I am new to R, but it has been a lot of fun learning as I go and have been blow 
away by what it can do.  Came across this example and wanted to see if ggplot2 
or some other visualization package could make this sort of graphic.

http://www.visualcomplexity.com/vc/project.cfm?id=717utm_source=feedburnerutm_medium=feedutm_campaign=Feed:+visualcomplexity+(visualcomplexity.com)utm_content=Google+Reader

Thanks in advance!

- Brock

__
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] It This data viz possible in R?

2010-04-07 Thread Barry Rowlingson
On Wed, Apr 7, 2010 at 2:28 PM, Brock Tibert btibe...@yahoo.com wrote:
 Hi All,

 I am new to R, but it has been a lot of fun learning as I go and have been 
 blow away by what it can do.  Came across this example and wanted to see if 
 ggplot2 or some other visualization package could make this sort of graphic.

 http://www.visualcomplexity.com/vc/project.cfm?id=717utm_source=feedburnerutm_medium=feedutm_campaign=Feed:+visualcomplexity+(visualcomplexity.com)utm_content=Google+Reader

 Thanks in advance!

 Not quite out-of-the box, but you can draw text with the text()
function setting the angle with the 'srt' parameter, and you can draw
lines using 'lines'. You can compute angles using 'pi'. You'll need a
bit of trig to work out the angle that the lines start and end at.
That's about all you need to know.

 Some of the subtleties of the typesetting of that specific piece may
be tricky, but it's easy to write a function that takes a vector of
strings and an adjacency matrix and plots something like it.

 Give R-help another hour and I reckon something will turn up. Not
from me, I'm watching the IPL cricket.

Barry

__
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] It This data viz possible in R?

2010-04-07 Thread baptiste auguie
Hi,

Barry suggested a way to place the text labels; I would like to point
out the grid.curve() function that might help in connecting the labels
with nice-looking curves. I don't know of a base graphics equivalent
(xspline() might come close) so it might be best to opt for Grid.

HTH,

baptiste


On 7 April 2010 15:46, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote:
 On Wed, Apr 7, 2010 at 2:28 PM, Brock Tibert btibe...@yahoo.com wrote:
 Hi All,

 I am new to R, but it has been a lot of fun learning as I go and have been 
 blow away by what it can do.  Came across this example and wanted to see if 
 ggplot2 or some other visualization package could make this sort of graphic.

 http://www.visualcomplexity.com/vc/project.cfm?id=717utm_source=feedburnerutm_medium=feedutm_campaign=Feed:+visualcomplexity+(visualcomplexity.com)utm_content=Google+Reader

 Thanks in advance!

  Not quite out-of-the box, but you can draw text with the text()
 function setting the angle with the 'srt' parameter, and you can draw
 lines using 'lines'. You can compute angles using 'pi'. You'll need a
 bit of trig to work out the angle that the lines start and end at.
 That's about all you need to know.

  Some of the subtleties of the typesetting of that specific piece may
 be tricky, but it's easy to write a function that takes a vector of
 strings and an adjacency matrix and plots something like it.

  Give R-help another hour and I reckon something will turn up. Not
 from me, I'm watching the IPL cricket.

 Barry

 __
 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-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] It This data viz possible in R?

2010-04-07 Thread Barry Rowlingson
On Wed, Apr 7, 2010 at 3:20 PM, baptiste auguie
baptiste.aug...@googlemail.com wrote:
 Hi,

 Barry suggested a way to place the text labels; I would like to point
 out the grid.curve() function that might help in connecting the labels
 with nice-looking curves. I don't know of a base graphics equivalent
 (xspline() might come close) so it might be best to opt for Grid.

 I'd just make circular arcs with sines and cosines.

 Of course the plot is a massive waste of space on a practical level.
Long names will squeeze the adjacency data into a smaller and smaller
area, making it harder to work out what is going on. I wouldn't want
to use this for anything else - but hey, that's what art is for :)

 Playing with this (before the Kolkata Knight Riders' innings just
started) and I hit a problem. You can't call strheight(X) to get the
text height without first doing plot.new, but you don't know how big
your plot is going to be until you know strheight(X). I'm sure
there's a way round this, but... Chris Gayle is batting.

Barry

__
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] It This data viz possible in R?

2010-04-07 Thread Gabor Grothendieck
There is draw.arc in the plotrix package.

On Wed, Apr 7, 2010 at 10:20 AM, baptiste auguie
baptiste.aug...@googlemail.com wrote:
 Hi,

 Barry suggested a way to place the text labels; I would like to point
 out the grid.curve() function that might help in connecting the labels
 with nice-looking curves. I don't know of a base graphics equivalent
 (xspline() might come close) so it might be best to opt for Grid.

 HTH,

 baptiste


 On 7 April 2010 15:46, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote:
 On Wed, Apr 7, 2010 at 2:28 PM, Brock Tibert btibe...@yahoo.com wrote:
 Hi All,

 I am new to R, but it has been a lot of fun learning as I go and have been 
 blow away by what it can do.  Came across this example and wanted to see if 
 ggplot2 or some other visualization package could make this sort of graphic.

 http://www.visualcomplexity.com/vc/project.cfm?id=717utm_source=feedburnerutm_medium=feedutm_campaign=Feed:+visualcomplexity+(visualcomplexity.com)utm_content=Google+Reader

 Thanks in advance!

  Not quite out-of-the box, but you can draw text with the text()
 function setting the angle with the 'srt' parameter, and you can draw
 lines using 'lines'. You can compute angles using 'pi'. You'll need a
 bit of trig to work out the angle that the lines start and end at.
 That's about all you need to know.

  Some of the subtleties of the typesetting of that specific piece may
 be tricky, but it's easy to write a function that takes a vector of
 strings and an adjacency matrix and plots something like it.

  Give R-help another hour and I reckon something will turn up. Not
 from me, I'm watching the IPL cricket.

 Barry

 __
 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-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-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] It This data viz possible in R?

2010-04-07 Thread baptiste auguie
The following grob might be a starting point. I couldn't find a clean
way of orienting the linking arcs though...

Best,

baptiste

library(grid)

paragraph - Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Praesent adipiscing lobortis placerat. Nunc vel arcu mauris. Aliquam
erat volutpat. Integer et pharetra orci. Sed rutrum facilisis dolor et
condimentum. Class aptent taciti sociosqu ad litora torquent per
conubia nostra, per inceptos himenaeos. Nunc leo nibh, pellentesque et
convallis quis, mattis ut mi. Nunc dignissim auctor elit pulvinar
malesuada. Cras dapibus hendrerit ligula quis suscipit. Proin porta
tempor feugiat. Ut quis nisi lacus, et egestas tortor. Fusce porttitor
tincidunt fringilla. Vivamus rhoncus ultrices elit, at fermentum nisl
scelerisque et. Duis placerat est at justo vestibulum sodales.
Curabitur quis eros tellus. 

words - strsplit(paragraph,  )[[1]]
labels - apply(matrix(words, ncol=3, byrow=T), 1, paste, collapse= )

arcTextGrob - function(x=unit(0.5, npc), y=unit(0.5, npc),
labels=letters[1:10],
links=sample(seq_along(labels), 10),
min.radius=unit(2, cm),
default.units=npc,
gp=gpar(), ...)
  {

## circle of perimeter = 1.5 * the text height
full.height - sum(stringHeight(labels))
radius - 1.5 /(2*pi) * full.height

g1 - circleGrob(0.5, 0.5, r=radius, default.units=npc)

## text labels
n - length(labels)
ang - seq(0, n-1) * 2 * pi/n

radius.mm - convertUnit(radius, npc, val=T)
coords - data.frame(x=0.5+radius.mm*cos(ang), y=0.5+radius.mm*sin(ang))
g2 - textGrob(labels, x=coords$x , y=coords$y , rot=ang*180/pi,
default.units=npc, hjust=0)

## links,
## NOTE: they are not well ordered...

xm - matrix(coords$x[links], ncol=2, byrow=T)
ym - matrix(coords$y[links], ncol=2, byrow=T)

g3 - do.call(gList, mapply(curveGrob, x1=xm[, 1], y1=ym[, 1],
x2=xm[, 2], y2=ym[, 2],
ncp=8, curvature=0.3, square=F, SIMPLIFY=FALSE))

gTree(children=gList(g1, g2, g3))
  }


grid.arcText - function(...)
  grid.draw(arcTextGrob(...))

dev.new()
grid.arcText(labels=labels)




On 7 April 2010 16:44, Gabor Grothendieck ggrothendi...@gmail.com wrote:
 There is draw.arc in the plotrix package.

 On Wed, Apr 7, 2010 at 10:20 AM, baptiste auguie
 baptiste.aug...@googlemail.com wrote:
 Hi,

 Barry suggested a way to place the text labels; I would like to point
 out the grid.curve() function that might help in connecting the labels
 with nice-looking curves. I don't know of a base graphics equivalent
 (xspline() might come close) so it might be best to opt for Grid.

 HTH,

 baptiste


 On 7 April 2010 15:46, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote:
 On Wed, Apr 7, 2010 at 2:28 PM, Brock Tibert btibe...@yahoo.com wrote:
 Hi All,

 I am new to R, but it has been a lot of fun learning as I go and have been 
 blow away by what it can do.  Came across this example and wanted to see 
 if ggplot2 or some other visualization package could make this sort of 
 graphic.

 http://www.visualcomplexity.com/vc/project.cfm?id=717utm_source=feedburnerutm_medium=feedutm_campaign=Feed:+visualcomplexity+(visualcomplexity.com)utm_content=Google+Reader

 Thanks in advance!

  Not quite out-of-the box, but you can draw text with the text()
 function setting the angle with the 'srt' parameter, and you can draw
 lines using 'lines'. You can compute angles using 'pi'. You'll need a
 bit of trig to work out the angle that the lines start and end at.
 That's about all you need to know.

  Some of the subtleties of the typesetting of that specific piece may
 be tricky, but it's easy to write a function that takes a vector of
 strings and an adjacency matrix and plots something like it.

  Give R-help another hour and I reckon something will turn up. Not
 from me, I'm watching the IPL cricket.

 Barry

 __
 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-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-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.