geom_fruit: geom_fruit

Description Usage Arguments Details Value Author(s) Examples

View source: R/geom_fruit.R

Description

plot tree associated data in another method.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
geom_fruit(
  mapping,
  data = NULL,
  geom,
  offset = 0.03,
  pwidth = 0.2,
  position = "auto",
  grid.params = NULL,
  axis.params = list(axis = "none", text.angle = 0, text.size = 0.8, text = NULL,
    nbreak = 4, line.size = 0.2, line.color = "grey", line.alpha = 1, ...),
  ...
)

fruit_plot(
  p,
  data = NULL,
  geom,
  mapping,
  offset = 0.03,
  pwidth = 0.2,
  position = "auto",
  ...
)

Arguments

mapping

aes mapping for 'geom'

data

data to plot by 'geom', the column contained tree tip labels should be as y in mapping.

geom

geom function to plot the data.

offset

numeric, distance between panels, the ratio of distance to tree, default is 0.03.

pwidth

numeric, the width of new geom layer, this is the ratio of the new geom to tree, default is 0.2.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function, default is 'auto'.

grid.params

list, the parameters to control the attributes of grid lines, default is NULL.

axis.params

list, the parameters to control the attributes of pseudo axis.

...

additional parameters for 'geom'

grid.params control the attributes of grid line, it can be referred to the following parameters:

  • vline logical, weather add the vertical line, default is FALSE.

  • color color of line, default is grey.

  • size the width of line, default is 0.2.

  • alpha the colour transparency of line, default is 1.

  • lineend Line end style (round, butt, square), default is "butt".

  • linejoin Line end style (round, butt, square), default is "round".

  • linetype Type of line, default is 1.

axis.params control the attributes of pseudo axis, it can be referred to the following parameters:

  • axis character, add the pseudo axis, "none" don't display axis (default), "x" display the x axis, "y" display the (y) axis of tree tip, "xy" display the two axis.

  • text vector, the text of axis x, default is NULL, it is only valid when the text of axis is single and x is discrete.

  • vjust numeric, A numeric specifying vertical justification, default is 0.5.

  • hjust numeric, A numeric specifying horizontal justification, default is 0.5.

  • text.angle numeric, the angle of axis text, default is 0.

  • text.size numeric, the size of axis text, default is 0.8.

  • nbreak numeric, meaning the number of axis to break, integer giving the desired number of intervals. Non-integer values are rounded down. It is only valid when x is continuous, default is 4.

  • line.size numeric, the size of axis line, default is 0.2.

  • line.color character, the color of axis color, default is "grey".

  • line.alpha numeric, the colour transparency of line, default is 1.

p

tree view

Details

'geom_fruit()' automatically re-arranges the input 'data' according to the tree structure, visualizes the 'data' on specific 'panel' using the 'geom' function with aesthetic 'mapping' and other parameters, and align the graph with the tree 'p' side by side. The default position parameters is 'auto'. If you want to set manually. You can use 'position_stackx()' or 'position_dodgex()' for 'geom_bar', 'position_identityx()' for 'geom_tile', 'geom_point', 'geom_star', 'geom_symbol' or other layers using 'identity' position in 'ggplot2', and 'position_dodgex()' or 'position_dodgex2()' for 'geom_boxplot' 'geom_violin' or other layers using 'dodge' position in 'ggplot2'. The axis line and text can be added using 'axis.params=list(axis="x",...)', and the grid line also can be added using 'grid.params=list(...)'.

Value

ggplot object

Author(s)

Shuangbin Xu and Guangchuang Yu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(ggtree)
library(ggplot2)
library(ggstar)
set.seed(1024)
tr <- rtree(100)
dd = data.frame(id=tr$tip.label, value=abs(rnorm(100)))
dt = data.frame(id=tr$tip.label, group=c(rep("A",50),rep("B",50)))
p <- ggtree(tr, layout="circular") 

p1 <- p + 
      geom_fruit(
          data=dt,
          geom=geom_star,
          mapping=aes(y=id, fill=group),
          size=2.5,
          starstroke=0
      )
p2 <- p1 + 
      geom_fruit(
          data=dd, 
          geom=geom_bar, 
          mapping=aes(x=value, y=id),
          orientation="y",
          stat="identity"
      )  

p3 <- fruit_plot(
           p=p, 
           data=dt, 
           geom=geom_star,
           mapping=aes(y=id, fill=group),
           size=2.5, 
           starstroke=0
      )

p4 <- fruit_plot(
           p=p3,
           data=dd,
           geom=geom_bar,
           mapping=aes(x=value, y=id),
           orientation="y",
           stat="identity"
      )
p <- p %<+% dd %<+% dt
p5 <- p + 
      geom_fruit(
          geom = geom_star,
          mapping = aes(y=id, fill=group),
          size = 2.5,
          starstroke = 0
      ) +
      geom_fruit(
          geom = geom_bar,
          mapping = aes(x=value, y=id),
          orientation = "y",
          stat = 'identity'
      )

ggtreeExtra documentation built on Nov. 8, 2020, 7:29 p.m.