Re: [R] graphically representing frequency of words in a speech?

2009-06-07 Thread Gorjanc Gregor
> The only thing that I found for R is by Gregor Gorjanc, but the
> information seems to be dated:
>
>http://www.bfro.uni-lj.si/MR/ggorjan/software/R/index.html#tagCloud

Hi,

Yes, I have tried to create a tag cloud plot in R, but I abandoned the project
due to other things. The main obstacle was that in R we need to take
care of the fontsizes and placement of words, while this is very easy with
say browsers, who do all the renderind. I tracked the last version of the R file
which is pasted bellow. I must say that I do not remember the status of the
code so use it as you wish. If anyone wishes to take this project further, 
please
do so!

gg

### tagCloud.R
###
### What: Tag cloud plot functions
### Time-stamp: <2006-09-10 02:53:29 ggorjan>
###

tagCloud <- function(x, n=100, decreasing=TRUE,
 threshold=NULL, fontsize=c(12, 36),
 align=TRUE, expandRow=TRUE,
 justRow="bottom", title,
 textGpar=gpar(col="navy"),
 rectGpar=gpar(col="white"),
 titleGpar=gpar(), viewGpar=gpar(),
 mar=c(1, 1, 1, 1))
{
  UseMethod("tagCloud")
}

tagCloud.default <- function(x, n=100, decreasing=TRUE,
 threshold=NULL, fontsize=c(12, 36),
 align=TRUE, expandRow=TRUE,
 justRow="bottom", title,
 textGpar=gpar(col="navy"),
 rectGpar=gpar(col="white"),
 titleGpar=gpar(), viewGpar=gpar(),
 mar=c(1, 1, 1, 1))
{
  if(!is.null(dim(x))) stop("'x' must be a vector")

  tagCloud.table(table(x), n=n, decreasing=decreasing, fontsize=fontsize,
 threshold=threshold, align=align, expandRow=expandRow,
 justRow=justRow, title=title, textGpar=textGpar,
 rectGpar=rectGpar, titleGpar=titleGpar, viewGpar=viewGpar,
 mar=mar)
}

tagCloud.table <- function(x, n=100, decreasing=TRUE,
   threshold=NULL, fontsize=c(12, 36),
   align=TRUE, expandRow=TRUE,
   justRow="bottom", title,
   textGpar=gpar(col="navy"),
   rectGpar=gpar(col="white"),
   titleGpar=gpar(), viewGpar=gpar(),
   mar=c(1, 1, 1, 1))
{
  ## --- Check ---

  if(length(dim(x)) != 1)
stop("'x' must be one dimensional table")

  ## --- Threshold ---

  if(!is.null(threshold)) x <- x[x >= threshold]

  ## --- Number of units ---

  N <- length(x)## length of table
  if(is.null(n)) {  ## if n=NULL, plot all units
n <- N
  } else {
if(n > N) n <- N## if n is to big, decrease it
if(n < 1) n <- round(N * n) ## if n is percentage of units
  }

  fontsizeLength <- length(fontsize)
  if(fontsizeLength != 2)
stop("'fontsize' must be of length two")

  ## --- Sort and subset ---

  if(n < N) { ## only if we want to plot subset of units
tmp <- sort(x, decreasing=decreasing)
x <- x[names(x) %in% names(tmp[1:n])]
  }

  ## --- Get relative freq ---

  x <- prop.table(x)

  ## --- Fontsize ---

  fontsizeDiff <- diff(fontsize)
  xDiff <- max(x) - min(x)
  if(xDiff != 0) {
off <- ifelse(fontsizeDiff > 0, min(x), max(x))
fontsize <- (x - off) / xDiff * fontsizeDiff + min(fontsize)
  } else { ## all units have the same frequency
fontsize <- rep(min(fontsize), times=n)
  }

  ## --- Viewport and rectangle ---

  grid.newpage()
  width <- unit(1, "npc")
  height <- unit(1, "npc")
  vp <- viewport(y=unit(mar[1], "lines"), x=unit(mar[2], "lines"), ,
 width=width - unit(mar[2] + mar[4], "lines"),
 height=height - unit(mar[1] + mar[3], "lines"),
 just=c("left", "bottom"), gp=viewGpar, name="main")
  pushViewport(vp)

  if(!missing(title))
grid.text(title, y=height, gp=titleGpar, name="title")

  grid.rect(gp=rectGpar, name="cloud")

  ## --- Grobs ---

  tag <- vector(mode="list", length=4)
  names(tag) <- c("fontsize", "grob", "width", "height")
  tag[[1]] <- tag[[2]] <- tag[[3]] <- tag[[4]] <- vector(mode="list", length=n)
  for(i in 1:n) {
tag$fontsize[[i]] <- fontsize[i]
tag$grob[[i]] <- textGrob(names(x[i]), gp=gpar(fontsize=fontsize[i]))
tag$width[[i]] <- convertWidth(grobWidth(tag$grob[[i]]), unitTo="npc",
   valueOnly=TRUE)
tag$height[[i]] <- convertHeight(grobHeight(tag$grob[[i]]), unitTo="npc",
 valueOnly=TRUE)
  }

  ## --- Split lines ---

  row <- colWidth <- vector(length=n)
  row[1] <- 1
  colWidth[1] <- 0
  lineWidth <- tag$width[[1]]
  j <- 1
  gapWidth <- convertWidth(stringWidth(" "), u

Re: [R] [Solved] Re: Sweave from Kile

2008-10-14 Thread Gorjanc Gregor
Hi Matthieu!

I am glad you solved your problem.

> Now I can compile direct from Kile! The only problem is that the command
> -ld only create the pdf, does not open it. Maybe are there other options
> from Script File of Gregor Gorjanc to compile with pdflatex (texi2dvi
> did not work) and open but I just made it from Kile: Settings->Configure
> Kile->Tools->Build->New Tool, configure it based on Archive for example,
> put the new command sweave  and then add any command to open (viewpdf in
> my case).

There are several arguments one can use with Sweave.sh. Try

Sweave.sh --help and you will get the help informtion.

Here is the relevant part about ways of compiling LaTeX and about direct
opening with Acrobat Reader or similar applications.

There are now the following ways of LaTeX processing:

  Command and path Script option Used tools
   - texi2dvi
  - PS  -tp, --texi2dvi2ps   texi2dvi and dvips
  - PS to PDF   -tld, --texi2dvi2ps2pdf  texi2dvi, dvips and ps2pdf
  - PDF -td, --texi2dvi2pdf  texi2dvi with pdf option

   - latex
  - PS  -lp, --latex2dvi2ps  hardcoded set of 'latex and 
friends' and dvips
  - PS to PDF   -lld, --latex2dvi2ps2pdf hardcoded set of 'latex and 
friends', dvips and ps2pdf

   - pdflatex
  - PDF -ld, --latex2pdf hardcoded set of 'pdflatex and 
friends'

Open produced files (PDF or Postscript) via options bellow, which are
one step further of options above and always imply them:

-otp=gv, --opentexi2dvi2ps=gv
-otld=acroread, --opentexi2dvi2ps2pdf=acroread
-otd=acroread, --opentexi2dvi2pdf=acroread
-olp=gv, --openlatex2dvi2ps=gv
-olld=acroread, --openlatex2dvi2ps2pdf=acroread
-old=acroread, --openlatex2pdf=acroread
  Files are opened with given application. Defaults are values taken
  from environmental variables PDFAPP and PSAPP. If these are not
  defined 'acroread' is taken for PDF and 'gv' for Postscript. Quotes
  are necessary in case of "bad" filenames.

gg

__
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] Sweave from Kile

2008-10-13 Thread Gorjanc Gregor
Hi Matthieu,

> Does anybody have experience with Sweave run from Kile? I'm trying to
> make it run but have problems and don't know if the instructions are
> false or I do something wrong (my knowledge in bash and shell is too low
> to understand it)...
...

It would help if you stated that you use "mine" Sweave.sh i.e. the one from
http://cran.r-project.org/contrib/extra/scripts/Sweave.sh. I will assume you
do.

I will start with the second problem

> 2: If I run kile with sudo (sudo Kile), the problem disappears but a new
>one comes
>> SweaveOnly output:
>> * cd '/media/Partition_Commune/Mes documents/Ordi/LaTex/Sweave'
>> * Sweave.sh −ld '\example1Leisch.Rnw'
>> *
>> Run Sweave and postprocess with LaTeX directly from command line
>> −ld is not a supported file type!
>> It should be one of: .lyx, .Rnw, .Snw., .nw or .tex
> Is the instructions false? Or do I do something wrong?

Is there a single - or double - i.e. --. If I issue the following

$ Sweave.sh --ld test.Rnw

Run Sweave and postprocess with LaTeX directly from command line

--ld is not a supported file type!
It should be one of: .lyx, .Rnw, .Snw., .nw or .tex

I get the same error.

> 1: finished with exit status 126
>> SweaveOnly output:
>> * cd '/media/Partition_Commune/Mes documents/Ordi/LaTex/Sweave'
>> * Sweave.sh −ld '\example1Leisch.Rnw'
>> *
>> /bin/bash: /usr/local/bin/Sweave.sh: Permission non accordée
> in english: permission not given

It seems that chmod did not behave as you expected. First check file
permissions with

ls -l /usr/local/bin/Sweave.sh

On my computer I get

-rwxr-xr-x 1 root root 30K 2008-04-30 11:17 /usr/local/bin/Sweave.sh*

Note that x is there three times i.e. anyone can run this script, the user, the
group and others.

Try with

sudo chmod a+x /usr/local/bin/Sweave.sh

and check the file permissions.

gg
__
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] rbugs on linux and wine

2008-04-22 Thread Gorjanc Gregor
> Gregor Gorjanc wrote:
>> Hi Alexander!
>>
>> You are mixing WinBUGS and OpenBUGS. R package Rbugs works with OpenBUGS, but
>> the later does not work with Rbugs under Linux!
>
> Are you talking about rbugs or BRugs, Gregor?

Ouch. Thank you Uwe! You are right, there are two R packages: rbugs and BRugs. 
Unfortunatelly,
I do not have eany xperience with rbugs.

Sorry.

g

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