[R] [FORGED] Re: Change the position of label when using R package eulerr

Paul Murrell p@u| @end|ng |rom @t@t@@uck|@nd@@c@nz
Mon Sep 17 05:00:01 CEST 2018


Hi

The 'x' component of the 't' grob that you get back from grid.get() is a 
unit object, which you can subset and assign to a subset, for example 
this code nudges the fourth label up and to the right 1mm in each 
direction ...


x <- t$x
y <- t$y

x[4] <- t$x[4] + unit(1, "mm")
y[4] <- t$y[4] + unit(1, "mm")

grid.edit("quantities.grob", x=x, y=y)


... is that the sort of thing you were looking for ?

Paul

On 15/09/18 09:03, Aimin Yan wrote:
> Thank you,
> 
> I figure out a way like this:
> 
> fit1 <- euler(c("ciLAD" = 785, "LAD" = 565, "nonXL_MEF" = 167,
>                      "ciLAD&LAD" = 3, "ciLAD&nonXL_MEF" = 101,
> "LAD&nonXL_MEF" = 541,
>                      "ciLAD&LAD&nonXL_MEF" = 2),shape = "ellipse")
> 
> plot(fit1,quantities = TRUE,fill = rainbow(7),lty = 1:2,labels = list(font
> = 1),alpha=0.7)
> 
> grid.ls()
> t <- grid.get("quantities.grob")
> names(t)
> 
> # Change these value will change the location of label.
> 
> grid.edit("quantities.grob",x=unit.c(unit(-14.9884684724791, "native"),
>                                           unit(-14.883684319653, "native"),
>                                           unit(13.9805892820006, "native"),
>                                           unit(-12.8808987356981, "native"),
>                                           unit(-11.488226371243, "native"),
>                                           unit(-9.51474016085318, "native"),
>                                           unit(-1.00436055190216, "native")))
> 
> grid.edit("quantities.grob",y=unit.c(unit(-8.07672595120493, "native"),
>                                           unit(4.78718651828883, "native"),
>                                           unit(0.25941593099694, "native"),
>                                           unit(-4.32200781461293, "native"),
>                                           unit(25.7349463488991, "native"),
>                                           unit(-22.7610031110325, "native"),
>                                           unit(14.5001560838519, "native")))
> 
> However, here I just want to change the x and y  value of 4th label, does
> anyone know how to set it?
> 
> Aimin
> 
> On Thu, Sep 13, 2018 at 9:56 PM David Winsemius <dwinsemius using comcast.net>
> wrote:
> 
>>
>>> On Sep 13, 2018, at 2:31 PM, Aimin Yan <aimin.at.work using gmail.com> wrote:
>>>
>>> I am using eulerr to get venn.
>>> My code is like:
>>>
>>> fit1 <- euler(c("ciLAD" = 785, "LAD" = 565, "nonXL_MEF" = 167,
>>>                     "ciLAD&LAD" = 3, "ciLAD&nonXL_MEF" = 101,
>>> "LAD&nonXL_MEF" = 541,
>>>                     "ciLAD&LAD&nonXL_MEF" = 2),shape = "ellipse")
>>>
>>> plot(fit1,quantities = TRUE,fill = rainbow(7),lty = 1:2,labels =
>> list(font
>>> = 1),alpha=0.7)
>>>
>>> After I get the figure, I find the position of some  labels need to be
>>> adjusted.
>>>
>>> Does anyone has some idea about how to process this?
>>
>> Looking at the code of plot.euler we see that the plotting paradigm is
>> grid. So you could assign the output to a data.object name, search for list
>> items that match the names of the labels you want to reposition, and modify
>> the position values. You would need to be more specific, if you want a
>> worked example.
>>
>> As far as I can see the lables and postions are fairly deep inside a list
>> structure:
>>
>>   $ children     :List of 1
>>    ..$ GRID.gTree.12:List of 5
>>    .. ..$ children
>>           $ diagram.grob.1
>>              $children
>> .. .. .. .. ..$ labels.grob    :List of 11
>>    .. .. .. .. .. ..$ label        : chr [1:3] "ciLAD" "LAD" "nonXL_MEF"
>>    .. .. .. .. .. ..$ x            : 'unit' num [1:3] -18.1native
>> 69.2native 11.9native
>>    .. .. .. .. .. .. ..- attr(*, "valid.unit")= int 4
>>    .. .. .. .. .. .. ..- attr(*, "unit")= chr "native"
>>    .. .. .. .. .. ..$ y            : 'unit' num [1:3] -17.86native
>> 5.24native 27.86native
>>    .. .. .. .. .. .. ..- attr(*, "valid.unit")= int 4
>>    .. .. .. .. .. .. ..- attr(*, "unit")= chr "native"
>>
>> --
>> David.
>>>
>>>
>>> Thank you,
>>>
>>> Aimin
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> 'Any technology distinguishable from magic is insufficiently advanced.'
>>   -Gehm's Corollary to Clarke's Third Law
>>
>>
>>
>>
>>
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul using stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list