Re: [R] PDF fonts problem

2008-09-19 Thread Mihalicza Péter

Dear Dr. Murrel,

Thank you for all the clarifications!

Paul Murrell írta:

Hi




#CMS
pdf("tryfont-cms.pdf", family="CMS")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#u151 and u171 doesn't show, though the other accented ones do

embedFonts("tryfont-cms.pdf",
outfile="tryfont-cms-embed.pdf",
fontpaths="/cm-super/afm/")
#after embedding the same "slipping" occurs



The 'fontpaths' argument describes where the PFB files are, not where 
the AFM files are.  So this is probably failing to embed the fonts 
because it can't find the fonts.  Does it work if you change to 
something like ...


 embedFonts("tryfont-cms.pdf",
   outfile="tryfont-cms-embed.pdf",
   fontpaths="cm-super/pfb/")

Paul


This solved my problem, so I am really very grateful! I am not too 
familiar with font protocols.
Just for the sake of knowledge: if my embedFonts specification should 
not have made any difference, why did the output pdf differed from the 
one before embedding?


Thanks again,
Peter



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

__
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] PDF fonts problem

2008-09-18 Thread Mihalicza Péter

Dear List,

I am writing a paper in Hungarian, that I Sweave and than pdfLaTeX. 
Everything is fine, except for two accented letters in the graphs that 
behave strange, though on the screen and in eps exports they look 
perfect. The problem is that I need pdf graphs, since I would like to 
have a PDF after LaTeX-ing.

For the example below I downloaded the following two font sets:
1. Latin Modern from http://www.ctan.org/get/fonts/lm.zip
2. Computer Moder Super from 
http://www.ctan.org/get/fonts/ps-type1/cm-super.zip
Both are specifically made for Eastern European languages (among many 
other).


The example is (I hope it is fully reproducible):

Sys.setlocale(category="LC_CTYPE", locale="hungarian")

LM <- Type1Font("LM", paste("lm/fonts/afm/public/lm/", c("lmb10.afm", 
"lmbx10.afm", "lmbo10.afm", "lmbxo10.afm"), sep=""))

pdfFonts(LM=LM)
postscriptFonts(LM=LM)

CMS <- Type1Font("CMS", paste("cm-super/afm/", c("sfrm1000.afm", 
"sfrb1000.afm", "sfti1000.afm", "sfsl1000.afm"), sep=""))

pdfFonts(CMS=CMS)
postscriptFonts(CMS=CMS)

#Default
pdf("tryfont-default.pdf")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#The u151 and the u171 characters "slips into" the characters following 
them ("h" and "l")


postscript("tryfont-default.eps")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#everything is perfect

#CMS
pdf("tryfont-cms.pdf", family="CMS")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#u151 and u171 doesn't show, though the other accented ones do

embedFonts("tryfont-cms.pdf",
outfile="tryfont-cms-embed.pdf",
fontpaths="/cm-super/afm/")
#after embedding the same "slipping" occurs

postscript("tryfont-cms.eps", family="CMS")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#everything is perfect

#LM
pdf("tryfont-lm.pdf", family="LM")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#same as CMS

embedFonts("tryfont-lm.pdf",
outfile="tryfont-lm-embed.pdf",
fontpaths="lm/fonts/afm/public/lm/")
#same as CMS

postscript("tryfont-LM.eps", family="LM")
grid.text("gg\u151hh\uF6ii\uF3jj kk\u171ll\uFCmm\uFAnn")
dev.off()
#same as CMS

After trying all this, I am out of ideas.
Could anyone suggest a solution?

> sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=Hungarian_Hungary.1250;LC_CTYPE=Hungarian_Hungary.1250;LC_MONETARY=Hungarian_Hungary.1250;LC_NUMERIC=C;LC_TIME=Hungarian_Hungary.1250

attached base packages:
[1] datasets  utils stats graphics  grDevices splines   grid
[8] methods   base


other attached packages:
[1] ggplot2_0.6colorspace_0.95RColorBrewer_1.0-2 
MASS_7.2-44  
[5] proto_0.3-8reshape_0.8.0  Hmisc_3.4-3  


loaded via a namespace (and not attached):
[1] cluster_1.11.11 lattice_0.17-13


Thank you,
Peter

--
Peter Mihalicza
economist

National Institute for Strategic Health Research
6-8. Arany János utca, Budapest-1051, Hungary
www.eski.hu

Tel.: +36-1-354-5320
E-mail: [EMAIL PROTECTED]



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

__
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] label outliers in geom_boxplot (ggplot2)

2008-06-06 Thread Mihalicza Péter

hadley wickham írta:

2008/5/27 Mihalicza Péter <[EMAIL PROTECTED]>:
  

Dear List and Hadley,

I would like to have a boxplot with ggplot2 and have the outlier values
labelled with their "name" attribute. So I did
> library(ggplot2)
  > dat=data.frame(num=rep(1,20), val=c(runif(18),3,3.5),
name=letters[1:20])
  > p=ggplot(dat, aes(y=val, x=num))+geom_boxplot(outlier.size=4,
outlier.colour="green")
  > p+geom_text(label=dat$name)

But this -of course- labels all the data points. So I searched high and low
to find the way to only label the outliers, but I couldn't find any
solution. Probably my keywords were inappropriate, but I looked at the
ggplot website and  the book also. So I did this:
> boxout=boxplot(dat$val)$out
  > outname=as.character(dat$name)
  > outname[(dat$val %in% boxout)==FALSE]="\n"
  > p+geom_text(label=outname)

This works, but seems like a hack to me. Is there an obvious solution that I
am missing?



I don't think so.  This type of problem (where you need to
independently access the statistics generated by ggplot) does come up
fairly often, but I don't have any particularly good solution for it.
  
It's too obvious, so I am positive that there is a good reason for not 
doing this, but still:
why is it not possible, to have an "outlier" output in stat_boxplot that 
can be used at geom_text()?


Something like this, with "upper":
   > dat=data.frame(num=rep(1,20), val=c(runif(18),3,3.5), 
name=letters[1:20])

   > ggplot(dat, aes(y=val, x=num))+stat_boxplot(outlier.size=4,
   + outlier.colour="green")+geom_text(aes(y=..upper..), label="This is 
upper hinge")


Unfortunately, this does not work and gives the error message:
   Error in eval(expr, envir, enclos) : object "upper" not found

Is it because you can only use stat outputs within the stat statements? 
Could it be possible to make them available outside the statements too?



P.S.  Sorry for taking so long to respond, I've been at my sister's
wedding in New Zealand
  

Thanks for the answer and happy marriage to your sister!

Peter



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

__
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] Odp: aggregate function oddity

2007-09-18 Thread Mihalicza Péter
Sorry for the confusion, I was not clear enough, so I made a small 
example to illustrate:

 >m=data.frame(fac1=rep(c(1,2),3), fac2=c("a","b","b","b","a","b"), 
num1=1:6, num2=7:12)
 > m$fac1=as.factor(m$fac1)
 > m
  fac1 fac2 num1 num2
11a17
22b28
31b39
42b4   10
51a5   11
62b6   12
 >#I would like to get the sum of num1 and num2 grouped by c(1,2) and c(a,b)
 > ag=aggregate(m, list(m$fac1, m$fac2), sum)
Error in Summary.factor(..., na.rm = na.rm) :
sum not meaningful for factors

 >#I understand, that it is possible to do...

 >ag=aggregate(m[,3:4], list(m$fac1, m$fac2), sum)
 > ag
  Group.1 Group.2 num1 num2
1   1   a6   18
2   1   b39
3   2   b   12   30

but I do not understand why aggragate tries to sum fac1 and fac2 since 
they are grouping variables that need not, and must not be summed. To my 
understanding the aggregate help text also does not speak about omitting 
factor variables from the data frame.

My question is whether I miss something, or this is how aggregate works. 
If the latter, than what is the reason for it.

Thanks, and sorry again!

Yours,
Peter Mihalicza



Petr PIKAL írta:
> Hi
>
> [EMAIL PROTECTED] napsal dne 17.09.2007 14:29:17:
>
>   
>> Dear All,
>>
>> I tried to aggregate the rows according to some factors in a data frame. 
>> 
>
>   
>> I got the
>> "Error in Summary.factor(..., na.rm = na.rm) :
>> sum not meaningful for factors"
>> message. This problem was once already discussed in 2003 on this list, 
>> where the following solution was given: include only those columns -when 
>> 
>
>   
>> giving it to aggregate() -  that are not factors.
>>
>> It also worked for me, but this solution is a bit odd, since there is no 
>> 
>
>   
>> need to sum the factors given as grouping variables. Of course I may do 
>> something completely wrong.
>> help(aggregate) says:
>> ## S3 method for class 'data.frame': aggregate(x, by, FUN, ...)
>> |x|an R object.
>> |by|a list of grouping elements, each as long as the variables in 
>> 
> |x|. 
>   
>> Names for the grouping variables are provided if they are not given. The 
>> 
>
>   
>> elements of the list will be coerced to factors (if they are not already 
>> 
>
>   
>> factors).
>>
>> In my interpretation this means that the factor variables and the 
>> numeric variables are in the same data frame, namely x.
>>
>> The data frame looks like this (its mortality from cerebrovascular 
>> diseases):
>>  > str(agyer)
>> 'data.frame':   102 obs. of  65 variables:
>>  $ Country: int  4055 4055 4055 4055 4055 4055 4055 4055 
>> 4055 4055 ...
>>  $ Name   : Factor w/ 5 levels "Estonia","Latvia",..: 1 1 1 
>> 1 1 1 1 1 1 1 ...
>>  $ Year   : int  1997 1997 1998 1999 1999 1999 2000 2000 
>> 2000 2001 ...
>>  $ List   : int  103 103 103 103 103 103 103 103 103 103 ...
>>  $ Sex: int  2 1 2 2 1 2 2 1 1 2 ...
>>  $ Morticd10_103_Frmat: int  1 1 1 1 1 1 1 1 1 1 ...
>>  $ IM_Frmat   : int  1 1 1 1 1 1 1 1 1 1 ...
>>  $ Deaths1: int  33 179 143 1428 83 61 3 759 29 4 ...
>> and a bunch of other int variables.
>>
>> After omitting agyer$Name, I do
>>  > agyerpr=aggregate(agyer, by=list(agyer$Country, agyer$Year, 
>> agyer$List, agyer$Sex, agyer$Morticd10_103_Frmat, agyer$IM_Frmat), sum)
>> 
>
> If this is the command you issued, it tries to aggregate the whole data 
> frame agyer including a factor variable Name, hence the error.
>
> You want probably to sum only Deaths column based on values in other 
> variables so you can do
>
> agyerpr <- with(agyer, aggregate(Deaths1, by=list(Country, Year,List,Sex, 
> Morticd10_103_Frmat, IM_Frmat), sum))
>
> Aggregate applies a function on each variable in R object, and if this 
> variable is not conforming to the function it will result in error.
> If you want to omit some columns from aggregation just put agyer[, 
> -c(column.numbers)] in x position of aggregate command.
>
>
> Regards
> Petr
>
>
>   
>> The sum is done on -the already omitted - factor of "Cause".
>>
>> I do not understand why it tries to sum a factor that is included in the 
>> 
>
>   
>> "by" list, since the concept is not to sum for those included, but use 
>> them for grouping. I am lucky with this database because all the factors 
>> 
>
>   
>> can be interpreted as integers and I do not have to onit them one by 
>> one, but what if not?
>>
>> Am I missing something with aggregate or classes?
>>
>> Thanks for your help!
>>
>> Sincerely,
>> Peter Mihalicza
>>
>>
>>
>> -- 
>> This message has been scanned for viruses and\ dangerous 
>> 
> con...{{dropped}}
>   
>> __
>> 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

[R] aggregate function oddity

2007-09-17 Thread Mihalicza Péter
Dear All,

I tried to aggregate the rows according to some factors in a data frame. 
I got the
"Error in Summary.factor(..., na.rm = na.rm) :
sum not meaningful for factors"
message. This problem was once already discussed in 2003 on this list, 
where the following solution was given: include only those columns -when 
giving it to aggregate() -  that are not factors.

It also worked for me, but this solution is a bit odd, since there is no 
need to sum the factors given as grouping variables. Of course I may do 
something completely wrong.
help(aggregate) says:
## S3 method for class 'data.frame': aggregate(x, by, FUN, ...)
|x| an R object.
|by|a list of grouping elements, each as long as the variables in |x|. 
Names for the grouping variables are provided if they are not given. The 
elements of the list will be coerced to factors (if they are not already 
factors).

In my interpretation this means that the factor variables and the 
numeric variables are in the same data frame, namely x.

The data frame looks like this (its mortality from cerebrovascular 
diseases):
 > str(agyer)
'data.frame':   102 obs. of  65 variables:
 $ Country: int  4055 4055 4055 4055 4055 4055 4055 4055 
4055 4055 ...
 $ Name   : Factor w/ 5 levels "Estonia","Latvia",..: 1 1 1 
1 1 1 1 1 1 1 ...
 $ Year   : int  1997 1997 1998 1999 1999 1999 2000 2000 
2000 2001 ...
 $ List   : int  103 103 103 103 103 103 103 103 103 103 ...
 $ Sex: int  2 1 2 2 1 2 2 1 1 2 ...
 $ Morticd10_103_Frmat: int  1 1 1 1 1 1 1 1 1 1 ...
 $ IM_Frmat   : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Deaths1: int  33 179 143 1428 83 61 3 759 29 4 ...
and a bunch of other int variables.

After omitting agyer$Name, I do
 > agyerpr=aggregate(agyer, by=list(agyer$Country, agyer$Year, 
agyer$List, agyer$Sex, agyer$Morticd10_103_Frmat, agyer$IM_Frmat), sum)

The sum is done on -the already omitted - factor of "Cause".

I do not understand why it tries to sum a factor that is included in the 
"by" list, since the concept is not to sum for those included, but use 
them for grouping. I am lucky with this database because all the factors 
can be interpreted as integers and I do not have to onit them one by 
one, but what if not?

Am I missing something with aggregate or classes?

Thanks for your help!

Sincerely,
Peter Mihalicza



-- 
This message has been scanned for viruses and\ dangerous con...{{dropped}}

__
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] aggregate function oddity

2007-09-17 Thread Mihalicza Péter

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