plotcli | R Documentation |
plotcli R6 Class
plotcli R6 Class
This class provides a set of methods to create and customize command-line plots using R6. It supports various plot types, such as scatter, line, bar, and box plots, and allows customization of plot elements, such as title, axis labels, ticks, and legend.
plotcli <- plotcli$new() plotcli$add_data(data) plotcli$print_plot()
Initializes the PlotCLI object with parameters.
Initializes the plot matrix with the plot canvas.
Default print method for PlotCLI object.
Adds a single row to the plot matrix.
Adds a single column to the plot matrix.
Adds borders around the plot canvas.
Adds row and column index to the plot matrix.
Adds a title to the plot matrix.
Adds y-axis tick labels to the plot matrix.
Adds a y-axis label to the plot matrix.
Adds x-axis tick labels to the plot matrix.
Adds an x-axis label to the plot matrix.
Adds a legend to the plot matrix.
Adds data to the object.
Gets minimum and maximum values for x and y.
Removes out of range data points if xlim and ylim were given.
Draws a scatter plot on the plot canvas.
Draws a line plot on the plot canvas.
Draws a bar plot on the plot canvas.
Draws a bar plot with braille characters on the plot canvas.
Draws a box plot on the plot canvas.
Assembles all plot elements and prints the plot to the console.
plot_width
The width of the plot
plot_height
The height of the plot
plot_canvas
The canvas for drawing the plot
plot_matrix
The matrix containing the entire plot, including borders, labels, and title
data
A list containing the data sets to be plotted
title
The title of the plot
x_label
The label for the x-axis
y_label
The label for the y-axis
ylim
The limits for the y-axis
xlim
The limits for the x-axis
x_min
The minimum value of the x-axis
x_max
The maximum value of the x-axis
y_min
The minimum value of the y-axis
y_max
The maximum value of the y-axis
plot_matrix_canvas_row_start
The starting row of the plot canvas within the plot matrix
plot_matrix_canvas_col_start
The starting column of the plot canvas within the plot matrix
is_boxplot
A logical value indicating if the plot is a boxplot
draw_legend
A logical value indicating if the legend should be drawn
new()
Initialize object
plotcli$new( plot_width = 60, plot_height = 20, x_label = "x", y_label = "y", ylim = NULL, xlim = NULL, title = NULL, is_boxplot = FALSE, draw_legend = TRUE )
plot_width
integer, width of the plot canvas
plot_height
integer, height of the plot canvas
x_label
character, label for the x-axis
y_label
character, label for the y-axis
ylim
numeric vector, limits for the y-axis
xlim
numeric vector, limits for the x-axis
title
character, title of the plot
is_boxplot
logical, whether the plot is a boxplot
draw_legend
logical, whether to draw the legend This function initializes the plot matrix based on the plot canvas.
initialize_plot_matrix()
Initialize the plot matrix
plotcli$initialize_plot_matrix()
plot_width
The width of the plot
plot_height
The height of the plot
A plot matrix object
print()
Default print method for plotcli object
plotcli$print(...)
...
Additional arguments passed to the print method
The plotcli object, invisibly
add_row()
Add a single row to the plot matrix
plotcli$add_row(bottom = FALSE)
bottom
logical, if TRUE, add row to the bottom of the matrix, otherwise add to the top (default: FALSE)
add_col()
Add a single column to the plot matrix
plotcli$add_col()
add_borders()
Add borders to the plot matrix
plotcli$add_borders()
add_row_col_index()
Add row and column index to the plot matrix Add title to the plot matrix
plotcli$add_row_col_index()
add_title()
plotcli$add_title()
title
character, title of the plot Add y-ticks label to the plot matrix
add_y_ticks()
plotcli$add_y_ticks(n_ticks = 5)
n_ticks
numeric, number of ticks Add y-axis label to the plot matrix
add_y_label()
Add a y-axis label to the plot matrix
plotcli$add_y_label(y_label = self$y_label)
y_label
character, the y-axis label to be added Add x-ticks label to the plot matrix
add_x_ticks()
plotcli$add_x_ticks(n_ticks = 5)
n_ticks
numeric, number of ticks Add x-axis label to the plot matrix
add_x_label()
Add x-axis label to the plot matrix
plotcli$add_x_label(x_label = self$x_label)
x_label
x label Add legend to the plot matrix
add_legend()
Add legend to the plot matrix Add data to the object.
plotcli$add_legend()
add_data()
plotcli$add_data(data)
data
list, list with elements: x, y, type, color, braille, name Get minimum and maximum values for x and y
get_min_max()
Calculate the minimum and maximum values for x and y Function to remove out of range data points if xlim and ylim were given
plotcli$get_min_max()
remove_out_of_range_data()
Remove data points that are outside the specified xlim and ylim Draw a scatter plot to the plot canvas.
plotcli$remove_out_of_range_data()
draw_scatter_plot()
Draw a scatter plot of the specified data set on the plot canvas.
plotcli$draw_scatter_plot(set_idx)
set_idx
numeric, the data element index to be drawn Draw a line plot to the plot canvas.
draw_line_plot()
plotcli$draw_line_plot(set_idx)
set_idx
numeric, the data element index to be drawn Draw a barplot to the plot canvas.
draw_barplot()
plotcli$draw_barplot(set_idx)
set_idx
numeric, the data element index to be drawn Draw a barplot to the plot canvas with braille characters.
draw_barplot_braille()
plotcli$draw_barplot_braille(set_idx)
set_idx
numeric, the data element index to be drawn Draw a boxplot to the plot canvas.
draw_boxplot()
plotcli$draw_boxplot(set_idx)
set_idx
numeric, the data element index to be drawn Draw colors to the canvas
draw_colors()
In the draw_ functions we have been keeping track of the locations of the colored matrix elements. These are now being colored. Draw the different plots types from all data elements to the canvas
plotcli$draw_colors()
draw_plot()
This function iterates through all data elements and calls the appropriate draw_ function based on the plot type (scatter, line, boxplot, or barplot). Make plot matrix: assembles all plot elements (canvas + borders + title + axes + legend)
plotcli$draw_plot()
make_plot_matrix()
This function assembles all plot elements (canvas + borders + title + axes + legend) and creates the final plot matrix. Export plot matrix
plotcli$make_plot_matrix()
export_plot_matrix()
This function exports the plot matrix.
plotcli$export_plot_matrix()
The plot matrix. Main plotting function: assembles all plot elements (canvas + borders + title + axes + legend) and prints the plot by 'cat'ing the plot matrix to the console.
print_plot()
This function assembles all plot elements (canvas + borders + title + axes + legend) and prints the final plot by 'cat'ing the plot matrix to the console. Merge two plotcli objects
This method combines the data from two plotcli objects into a single plotcli object. It takes the maximum of the plot_width and plot_height, combines the titles, and sets the xlim and ylim to the minimum and maximum values of both objects.
plotcli$print_plot()
merge()
plotcli$merge(other)
other
A plotcli object to be merged with the current object.
A new plotcli object containing the combined data from both objects.
clone()
The objects of this class are cloneable with this method.
plotcli$clone(deep = FALSE)
deep
Whether to make a deep clone.
# Create a new plotcli object
plotcli <- plotcli$new()
# Add data for a scatter plot
plotcli$add_data(list(x = 1:10, y = rnorm(10), type = "scatter", color = "red"))
# Print the plot
plotcli$print_plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.