View source: R/functions_scatterplot_with_side_density.R View source: R/functions_scatter_with_side_density.R
plot_scatter_side_density.xy | R Documentation |
plot a scatterplot with sets in color
plot_scatter_side_density.xy( xy_data, x_, y_, id_ = "id", set_ = "set", labs_x = x_, labs_y = y_, labs_sets = set_, main_title = NULL, main_title.x = 0.02, main_title.y = 0.5, main_title.hjust = 0, main_title.vjust = 0.5, sets.colors = NULL, bg.string = "background", bg.color = "gray70", sets.sizes = 1, bg.size = 0.5, xlim_ = NULL, ylim_ = NULL, n_auto_label = 8, manual_label = NULL, label_size = 2, label_color = "black", label_use_shadow = TRUE, label_use_ggrepel = TRUE, label_min.segment.length = 0.5, ref_line.x = 0, ref_line.x.color = "gray50", ref_line.y = 0, ref_line.y.color = "gray50", ref_line.slope = 1, ref_line.slope.color = "black", suppress_plot = FALSE, rel_widths = c(2, 1), rel_heights = c(1, 2) )
xy_data |
a data.table with columns determined by x_, y_, id_, set_. alternatively a data.frame or matrix whose rownames will be set to id_. |
x_ |
string specifiying column in xy_data whose values map to x-axis, default is "x" |
y_ |
string specifiying column in xy_data whose values map to y-axis, default is "y" |
id_ |
string specifiying column in xy_data whose values uniquely identify items, default is "id" |
set_ |
string specifiying column in xy_data whose values specify set membership, default is "set" |
labs_x |
string labelling x-axis, default is value of x_. |
labs_y |
string labelling y-axis, default is value of y_. |
labs_sets |
string labelling color and size, default is value of set_. |
main_title |
string for main title. default is NULL. |
main_title.x |
x coord of title, 0-1, default is 0.02 |
main_title.y |
y coord of title, 0-1, default is 0.5 |
main_title.hjust |
hjust of title, default is 0 |
main_title.vjust |
vjust of title, default is 0.5 |
sets.colors |
colors to map to each set. |
bg.string |
string specifying the background set. default is "background". background is always plotted at the bottom and omitted from density. |
bg.color |
string specifying color for background. |
sets.sizes |
sizes of each set. default is 1. repeated to number of sets. |
bg.size |
size of background points. default is 0.5. |
xlim_ |
optional manual override of xlimits. default is NULL. |
ylim_ |
optional manual override of ylimits. default is NULL. |
n_auto_label |
number of points to autolabel. picked based on distance from slope 1. |
manual_label |
manual specification by id_ of points to label. |
label_size |
size for item labels. |
label_color |
colors for item labels. |
ref_line.x |
any reference lines to include along x axis |
ref_line.x.color |
color of x axis reference lines |
ref_line.y |
any reference lines to include along y axis |
ref_line.y.color |
color of y axis reference lines |
ref_line.slope |
partially impelemented. if any numeric supplied, a line of slope 1 is drawn. |
ref_line.slope.color |
color for slop line. |
suppress_plot |
if TRUE, plot is not send to device. invisible output should be captured. |
label_GEOM |
geom function to use for labels. default is shadowtext::geom_shadowtext. consider, geom_label, ggrepel::geom_text_repel etc. |
a list of two intems, grob of assembled plot and a list of grobs for all components.
n = 50 xy_data = rbind( data.table(x = rnorm(10*n, 0, 1), y = rnorm(10*n, 0, 1), set = "background"), data.table(x = rnorm(2*n, 2, 1), y = rnorm(2*n, 0, 1), set = "set1"), data.table(x = rnorm(2*n, 0, 1), y = rnorm(2*n, 2, 1), set = "set2"), data.table(x = rnorm(2*n, 2, 1), y = rnorm(2*n, 2, 1), set = "set3") ) xy_data$id = seq_len(nrow(xy_data)) #by default, an assembled plot is output to graphic device plot_scatter_side_density.xy(xy_data, x_ = "x", y_ = "y") #a list with assembled plots and components are also returned for extra customization #here's an example with lots of extra options used plots = plot_scatter_side_density.xy(xy_data, x_ = "x", y_ = "y", suppress_plot = TRUE, ref_line.x = c(0, 2), ref_line.y = c(0, 2), ref_line.x.color = c("gray70", "forestgreen"), ref_line.y.color = c("gray70", "forestgreen"), labs_x = "fc x", labs_y = "fc y", labs_sets = "group", main_title = "an important plot") plots$assembled new_lim = c(-5, 10) comp = plots$components comp$scatter = comp$scatter + coord_cartesian(xlim = new_lim, ylim = new_lim) comp$x_density = comp$x_density + coord_cartesian(xlim = new_lim) comp$y_density = comp$y_density + coord_flip(xlim = new_lim) plot_scatter_side_density.assemble(comp, main_title = "new limits") xy_df = as.data.frame(xy_data[,1:3]) rownames(xy_df) = xy_data$id plot_scatter_side_density.xy(xy_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.