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

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Sun Sep 16 00:25:16 CEST 2018


> On Sep 15, 2018, at 1:27 PM, Aimin Yan <aimin.at.work using gmail.com> wrote:
> 
> Thank you, I tried your code, but I still got error:
> 
>   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")
>     
>     fit1.plot <- plot(fit1,quantities = TRUE,fill = rainbow(7),lty = 1:2,labels = list(font = 1),alpha=0.7)
>     fit1.plot
>     grid.ls(fit1.plot)

I don't think you are editing the right object (and I don't think you have honored my prior efforts to get you to read the documentation for the grid package):

names(fit1.plot)
#[1] "name"          "gp"            "vp"            "children"      "childrenOrder"
names(fit1.plot$children)
#[1] "GRID.gTree.12"
 names(fit1.plot$children$GRID.gTree.12)
#[1] "name"          "gp"            "vp"            "children"      "childrenOrder"
 names(fit1.plot$children$GRID.gTree.12$children)
#[1] "diagram.grob.1"
 names(fit1.plot$children$GRID.gTree.12$children$diagram.grob.1)
#[1] "name"          "gp"            "vp"            "children"      "childrenOrder"

 names()
 #[1] "fills.grob.1"    "fills.grob.2"    "fills.grob.3"    "fills.grob.4"    "fills.grob.5"    "fills.grob.6"    "fills.grob.7"   
 #[8] "edges.grob"      "labels.grob"     "quantities.grob"

My suggested target for editing, in place, would be:

fit1.plot$children$GRID.gTree.12$children$diagram.grob.1$children$quantities.grob

str( fit1.plot$children$GRID.gTree.12$children$diagram.grob.1$children$quantities.grob )
#----------------------
List of 11
 $ label        : chr [1:7] "3" "101" "541" "2" ...
 $ x            : 'unit' num [1:7] -4.35native -11.01native 16.5native -4.01native -28.09native ...
  ..- attr(*, "valid.unit")= int 4
  ..- attr(*, "unit")= chr "native"
 $ y            : 'unit' num [1:7] -2.569native 15.889native 4.732native -0.788native -7.157native ...
  ..- attr(*, "valid.unit")= int 4
  ..- attr(*, "unit")= chr "native"
 $ just         : chr "centre"
 $ hjust        : NULL
 $ vjust        : num [1:7] 0.5 0.5 0.5 0.5 1 1 1
 $ rot          : num [1:7] 0 0 0 0 0 0 0
 $ check.overlap: logi FALSE
 $ name         : chr "quantities.grob"
 $ gp           :List of 7
  ..$ col       : int [1:7] 1 1 1 1 1 1 1
  ..$ alpha     : num [1:7] 1 1 1 1 1 1 1
  ..$ fontsize  : num [1:7] 12 12 12 12 12 12 12
  ..$ cex       : num [1:7] 1 1 1 1 1 1 1
  ..$ fontfamily: chr [1:7] "" "" "" "" ...
  ..$ lineheight: num [1:7] 1.2 1.2 1.2 1.2 1.2 1.2 1.2
  ..$ font      : int [1:7] 1 1 1 1 1 1 1
  ..- attr(*, "class")= chr "gpar"
 $ vp           : NULL
 - attr(*, "class")= chr [1:3] "text" "grob" "gDesc"

 str( fit1.plot$children$GRID.gTree.12$children$diagram.grob.1$children$quantities.grob$x )
#----------
 'unit' num [1:7] -4.35native -11.01native 16.5native -4.01native -28.09native ...
 - attr(*, "valid.unit")= int 4
 - attr(*, "unit")= chr "native"
#-------
 str( fit1.plot$children$GRID.gTree.12$children$diagram.grob.1$children$quantities.grob$y )
#________
 'unit' num [1:7] -2.569native 15.889native 4.732native -0.788native -7.157native ...
 - attr(*, "valid.unit")= int 4
 - attr(*, "unit")= chr "native"

-- 
David




>     t <- grid.get("quantities.grob")
>     names(t)
>     t$label
>     t$x
>     t$y
> 
>     # Try to change the x and y value of the 4th label "2"
>     grid.edit("quantities.grob",x[[4]]=unit(-11.8262244206465, "native"))
>     grid.edit("quantities.grob",y[[4]]=unit(-5.19720701058398, "native"))
> 
> Error: unexpected '=' in "grid.edit("quantities.grob",x[[4]]="
> 
> Aimin
> 
> On Fri, Sep 14, 2018 at 6:47 PM David Winsemius <dwinsemius using comcast.net> wrote:
> 
> > On Sep 14, 2018, at 2:03 PM, Aimin Yan <aimin.at.work using gmail.com> 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?
> 
> If the t object were a complete grid object, it might have been:
> 
> grid.edit("quantities.grob", x[[4]]= unit(-12.8808987356981, "native")
>            )               
> grid.edit("quantities.grob", y[[4]]= unit(-4.32200781461293, "native"),
>            )
> 
> 
> But I don't think that will succeed since you never assigned the value of the plot operation to a name. Instead you pulled out part of the grid object that was sitting "free" and unassigned to a name. If you assign that value of plot(....) to `my.plot` you get:
> 
>  grid.ls(my.plot)
> euler.diagram
>   GRID.gTree.11
>     diagram.grob.1
>       fills.grob.1
>       fills.grob.2
>       fills.grob.3
>       fills.grob.4
>       fills.grob.5
>       fills.grob.6
>       fills.grob.7
>       edges.grob
>       labels.grob
>       quantities.grob
> 
> I think you need to work with the tutorials in the grid package.
> 
> Look at:
> 
> help("grid-package")
> 
> -- 
> David.
> 
> > 
> > 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
> > 
> > 
> > 
> > 
> > 
> 
> David Winsemius
> Alameda, CA, USA
> 
> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
> 
> 
> 
> 
> 

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law




More information about the R-help mailing list