This plot purpose is to illustrate how states change before and
after. In my research I use it before surgery and after surgery
but it can be used in any situation where you have a change from
one state to another
This should be a matrix with the size of the transitions.
The unit for each cell should be number of observations, row/column-proportions
will show incorrect sizes. The matrix needs to be square. The best way to generate
this matrix is probably just do a table(starting_state, end_state). The rows
represent the starting positions, while the columns the end positions. I.e. the first
rows third column is the number of observations that go from the first class to the
third class.
type_of_arrow
The types of arrow may be grid, simple, or gradient. Simple grid
arrows are the bezierGrob arrows (not that pretty),
simple is the bezierArrowSmpl that I've created to get a more exact
control of the arrow position and width, while gradient
corresponds to bezierArrowGradient
allowing the arrow to have a fill color that slowly turns into the color of the arrow.
box_txt
The text to appear inside of the boxes. If you need line breaks
then you need to manually add a \n inside the string.
tot_spacing
The proportion of the vertical space that is to be left
empty. It is then split evenly between the boxes.
box_width
The width of the box. By default the box is one fourth of
the plot width.
fill_start_box
The fill color of the start boxes. This can either
be a single value ore a vector if you desire different colors for each
box. If you specify box_prop then this has to be a 2 column matrix.
txt_start_clr
The text color of the start boxes. This can either
be a single value ore a vector if you desire different colors for each
box. If you specify box_prop then this has to be a 2 column matrix.
fill_end_box
The fill color of the end boxes. This can either
be a single value ore a vector if you desire different colors for each
box. If you specify box_prop then this has to be a 2 column matrix.
txt_end_clr
The text color of the end boxes. This can either
be a single value ore a vector if you desire different colors for each
box. If you specify box_prop then this has to be a 2 column matrix.
cex
The cex gpar of the text
min_lwd
The minimum width of the line that we want to illustrate the
tranisition with.
max_lwd
The maximum width of the line that we want to illustrate the
tranisition with.
lwd_prop_total
The width of the lines may be proportional to either the
other flows from that box, or they may be related to all flows. This is a boolean
parameter that is set to true by default, i.e. relating to all flows.
arrow_clr
The color of the arrows. Usually black, can be a vector indicating each arrow
from first to last arrow (counting from the top). If the vector is of the same length as the
boxes then all box arrows will have the same color (that is all the arrows stemming from the
left boxes)
abs_arrow_width
The width can either be absolute, i.e. each arrow headed for a box
has the exact same width. The alternative is that the width is related to the line width.
overlap_bg_clr
In order to enhance the 3D perspective and to make it easier
to follow arrows the arrows have a background color to separate them from those underneath.
overlap_order
The order from first->last for the lines. This means that the last
line will be on top while the first one will appear at the bottom. This should be provided
as a vector.
overlap_add_width
The width of the white cross-over line. You can specify this as a scalar
multiplication of the current line width. In case of non-grid arrows then you can also have this
as a unit which is recommended as it looks better. If the scalar is < 1 then the overlap is ignored.
box_prop
If you want the boxes to have proportions indicating some other factors then input
a matrix with quantiles for the proportions. Note the size mus be nrow(transition_flow) x 2.
mar
A numerical vector of the form c(bottom, left, top, right) of the type unit()
main
The title of the plot if any, default NULL
box_label
A vector of length 2 if you want to label each box column
box_label_pos
The position of the label, either 'top' or 'bottom'
box_label_cex
The cex of the label, defaults to the default cex
color_bar
If you have proportions inside the transition_flow variable
then the color_bar will automatically appear at the bottom unless you set
this to FALSE
color_bar_cex
The size of the tick labels for the color bar
color_bar_labels
The labels of the two proportions that make up the color bar.
Defaults to the labels of the third dimension for the transition_flow
argument.
color_bar_subspace
If there is little or no difference exists
at the low/high proportions of the spectrum then it
can be of interest to focus the color change to the center
leaving the tails constant
new_page
If you want the plot to appear on a new blank page then set this to TRUE, by
default it is FALSE.
Value
void
Examples
# This example does not run since it
# takes a little while to assemble the
# arrows and RMD Check complains that this
# is more than allowed for
library(grid)
par_org <- par(ask=TRUE)
# Settings
no_boxes <- 3
# Generate test setting
transition_matrix <- matrix(NA, nrow=no_boxes, ncol=no_boxes)
transition_matrix[1,] <- 200*c(.5, .25, .25)
transition_matrix[2,] <- 540*c(.75, .10, .15)
transition_matrix[3,] <- 340*c(0, .2, .80)
grid.newpage()
transitionPlot(transition_matrix,
box_txt = c("First", "Second", "Third"),
type_of_arrow = "simple",
min_lwd = unit(1, "mm"),
max_lwd = unit(6, "mm"),
overlap_add_width = unit(1, "mm"))
# Setup proportions
box_prop <- cbind(c(1,0,0.5), c(.52,.2,.8))
# From the Set2 Colorbrewer
start_box_clr <- c("#8DA0CB", "#FC8D62")
# Darken the colors slightly
end_box_clr <- c(colorRampPalette(c(start_box_clr[1], "#000000"))(10)[2],
colorRampPalette(c(start_box_clr[2], "#000000"))(10)[2])
# Create a new grid
grid.newpage()
transitionPlot(transition_matrix, box_prop=box_prop,
fill_start_box=start_box_clr, fill_end_box=end_box_clr,
txt_start_clr = c("#FFFFFF", "#000000"), txt_end_clr = c("#FFFFFF", "#000000"),
box_txt = c("First", "Second", "Third"),
type_of_arrow = "gradient",
min_lwd = unit(1, "mm"),
max_lwd = unit(10, "mm"),
overlap_add_width = unit(1, "mm"))
par(par_org)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Gmisc)
Loading required package: Rcpp
Loading required package: htmlTable
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Gmisc/transitionPlot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: transitionPlot
> ### Title: A transition plot
> ### Aliases: transitionPlot
>
> ### ** Examples
>
> # This example does not run since it
> # takes a little while to assemble the
> # arrows and RMD Check complains that this
> # is more than allowed for
> library(grid)
> par_org <- par(ask=TRUE)
> # Settings
> no_boxes <- 3
> # Generate test setting
> transition_matrix <- matrix(NA, nrow=no_boxes, ncol=no_boxes)
> transition_matrix[1,] <- 200*c(.5, .25, .25)
> transition_matrix[2,] <- 540*c(.75, .10, .15)
> transition_matrix[3,] <- 340*c(0, .2, .80)
>
> grid.newpage()
> transitionPlot(transition_matrix,
+ box_txt = c("First", "Second", "Third"),
+ type_of_arrow = "simple",
+ min_lwd = unit(1, "mm"),
+ max_lwd = unit(6, "mm"),
+ overlap_add_width = unit(1, "mm"))
The minimum width reached and the arrow at box no. '1' to no. '2' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
The minimum width reached and the arrow at box no. '1' to no. '3' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
The minimum width reached and the arrow at box no. '1' to no. '2' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
The minimum width reached and the arrow at box no. '1' to no. '3' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
The minimum width reached and the arrow at box no. '2' to no. '2' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
The minimum width reached and the arrow at box no. '2' to no. '2' will not be shown. This is due to the fact that the lwd will generate a falsely strong arrow.
>
>
> # Setup proportions
> box_prop <- cbind(c(1,0,0.5), c(.52,.2,.8))
> # From the Set2 Colorbrewer
> start_box_clr <- c("#8DA0CB", "#FC8D62")
> # Darken the colors slightly
> end_box_clr <- c(colorRampPalette(c(start_box_clr[1], "#000000"))(10)[2],
+ colorRampPalette(c(start_box_clr[2], "#000000"))(10)[2])
> # Create a new grid
> grid.newpage()
> transitionPlot(transition_matrix, box_prop=box_prop,
+ fill_start_box=start_box_clr, fill_end_box=end_box_clr,
+ txt_start_clr = c("#FFFFFF", "#000000"), txt_end_clr = c("#FFFFFF", "#000000"),
+ box_txt = c("First", "Second", "Third"),
+ type_of_arrow = "gradient",
+ min_lwd = unit(1, "mm"),
+ max_lwd = unit(10, "mm"),
+ overlap_add_width = unit(1, "mm"))
> par(par_org)
>
>
>
>
>
> dev.off()
null device
1
>