sp_scatterplot: Generating scatter plot

Description Usage Arguments Value Examples

Description

Generating scatter plot

Usage

 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
sp_scatterplot(
  data,
  xvariable = NULL,
  yvariable = NULL,
  label_variable = NULL,
  xvariable_order = NULL,
  yvariable_order = NULL,
  color_variable_order = NULL,
  shape_variable_order = NULL,
  manual_color_vector = NULL,
  log_variables = NULL,
  log_transform = "log2",
  size_variable = NULL,
  geom_text_repel = TRUE,
  shape_variable = NULL,
  color_variable = NULL,
  point_hjust = 0,
  line_size = NULL,
  smooth_method = "no smooth",
  alpha = 1,
  jitter = FALSE,
  jitter_text = F,
  scale_size_min = NULL,
  scale_size_max = NULL,
  coordinate_flip = FALSE,
  legend.position = "right",
  xtics_angle = 0,
  title = NULL,
  x_label = NULL,
  y_label = NULL,
  extra_ggplot2_cmd = NULL,
  label_font_size = 3,
  facet = NULL,
  nrow = NULL,
  ncol = NULL,
  scales = "fixed",
  scale_y_way = NULL,
  ...
)

Arguments

data

Data file or dataframe (with header line, the first column is not the rowname, tab seperated).

xvariable

The variable for x axis. NECESSARY, such X_val (one of column names), both text and number works.

yvariable

The variable for y axis. NECESSARY, such as Y_val (one of column names), both text and number works.

label_variable

Label points with given text. Default no-label, accept a string like Samp`` (one of column names) here to label Samp' column text to points.

xvariable_order

The order for x-axis when xvariables are text. Default alphabetical order, accept a string like c('K562','hESC','GM12878','HUVEC','NHEK','IMR90','HMEC').

yvariable_order

The order for y-axis when yvariables are text. Default alphabetical order, accept a string like c('K562','hESC','GM12878','HUVEC','NHEK','IMR90','HMEC').

color_variable_order

The order for color variable. Default alphabetical order, accept a string like c('K562','hESC','GM12878','HUVEC','NHEK','IMR90','HMEC').

shape_variable_order

The order for shape variable. Default alphabetical order, accept a string like c('K562','hESC','GM12878','HUVEC','NHEK','IMR90','HMEC').

manual_color_vector

Manually set colors for each geom. Default NULL, meaning using ggplot2 default. Colors like c('red', 'blue', '#6181BD') (number of colors not matter) or a RColorBrewer color set like "BrBG" "PiYG" "PRGn" "PuOr" "RdBu" "RdGy" "RdYlBu" "RdYlGn" "Spectral" "Accent" "Dark2" "Paired" "Pastel1" "Pastel2" "Set1" "Set2" "Set3" "Blues" "BuGn" "BuPu" "GnBu" "Greens" "Greys" "Oranges" "OrRd" "PuBu" "PuBuGn" "PuRd" "Purples" "RdPu" "Reds" "YlGn" "YlGnBu" "YlOrBr" "YlOrRd" (check http://www.sthda.com/english/wiki/colors-in-r for more).

log_variables

Get log-transformed data for given variable. Default NULL, means no log10 transform. Accept a vector like c('color') (one or several of column names) to get (-1) * log10(color).

log_transform

Get log-transformed data for log_variables. Default log2, means log2 transform if log_variabels are not null. Accept log10.

size_variable

The variable for point size. Optional, such as a number or a variable like count (one of column names), normally should be number column.

shape_variable

The variable for point shape. Optional, such as shape (one of column names).

color_variable

The variable for point color. Optional, such as color (one of column names).

line_size

line size. Default NULL. Accept a number.

smooth_method

The smooth method one wants to use, eg. auto, lm, glm, gam, loess, rlm. For observations < 1000 default is 'loess', observations >= 1000 defaults to 'gam'. Default 'no smooth' meaning show the real lines and do not smooth lines. Accept auto, lm, glm, gam, loess, rlm.

alpha

Transparency value for points. Optional, such as a number or a variable indicating one data column, normally should be number column (one of column names).

jitter

Jitter points. Normally used when x and y axis variable is in text format or represents group information to avoid point overlaps. Default FALSE.

jitter_text

Make point labels not overlap. Default FALSE.

scale_size_min

Scale size with minimum value specified

scale_size_max

Scale size with maximum value specified

coordinate_flip

Flip cartesian coordinates so that horizontal becomes vertical, and vertical, horizontal. This is primarily useful for converting geoms and statistics which display y conditional on x, to x conditional on y.

legend.position

Position of legend, accept top, bottom, left, right, none or c(0.8,0.8).

xtics_angle

Rotation angle for a-axis. Default 0.

title

Title of picture. Default empty title.

x_label

Xlab label.

y_label

Ylab label.

extra_ggplot2_cmd

Extra ggplot2 commands (currently unsupported)

label_font_size

Label font size. Default system default. Accept a number.

facet

Wrap plots by given column. This is used to put multiple plot in one picture. Used when melted is FALSE, normally a string set (one of column names) should be suitable for this parameter.

nrow

The number of rows one want when melted is used. Default NULL.

ncol

The number of columns one want when melted is used. Default NULL.

scales

Paramter for scales for facet. Default fixed meaning each inner graph

scale_y_way

The way to scale Y-axis like scale_y_log10, coord_trans(y="log10"), scale_y_continuous(trans="log2"), coord_trans(y="log2").

...

Parametes given to sp_ggplot_layout

Value

A ggplot2 object

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
scatter_test_data <- data.frame(Samp = letters[1:6], Color = sample(c("group1", "group2", "group3"),6,replace = TRUE),
X_val = runif(6), Y_val = runif(6), Size = sample(4:20, size = 6),
Shape = sample(c("cluster1","cluster2"),6,replace = TRUE))

sp_scatterplot(data=scatter_test_data,xvariable = "X_val",yvariable = "Y_val",
color_variable = "Color", shape_variable= "Shape",
size_variable = "Size",label="Samp",Jitter = TRUE)



## Not run:
scatter_data = "scatter.txt"
sp_scatterplot(data="scatter.txt",xvariable = "X_val",yvariable = "Y_val",
color_variable = "Color", shape_variable= "Shape",size_variable = "Size",
label="Samp", xvariable_order = c(1,3,2), yvariable_order = c(2,1,3),
color_variable_order = c("grp2","grp1","grp3"),
shape_variable_order = c("cluster2","cluster1"),label_font_size=2)

sp_scatterplot(data="scatter.txt",xvariable = "X_val",yvariable = "Y_val", color_variable = "Color", shape_variable= "Shape",
size_variable = "Size",label="Samp",Jitter = TRUE)

sp_scatterplot(data="scatter.txt",xvariable = "X_val",yvariable = "Y_val", color_variable = "Color", shape_variable= "Shape",
size_variable = "Size",label="Samp",Jitter = TRUE,facet = "Color", scales = "free_y")
## End(Not run)

Tong-Chen/YSX documentation built on Jan. 25, 2021, 2:49 a.m.