plotcli {plotcli} | R Documentation |
plotcli R6 Class
Description
plotcli R6 Class
plotcli R6 Class
Details
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.
Usage
plotcli <- plotcli$new() plotcli$add_data(data) plotcli$print_plot()
Methods
- initialize()
Initializes the PlotCLI object with parameters.
- initialize_plot_matrix()
Initializes the plot matrix with the plot canvas.
- print()
Default print method for PlotCLI object.
- add_row()
Adds a single row to the plot matrix.
- add_col()
Adds a single column to the plot matrix.
- add_borders()
Adds borders around the plot canvas.
- add_row_col_index()
Adds row and column index to the plot matrix.
- add_title()
Adds a title to the plot matrix.
- add_y_ticks()
Adds y-axis tick labels to the plot matrix.
- add_y_label()
Adds a y-axis label to the plot matrix.
- add_x_ticks()
Adds x-axis tick labels to the plot matrix.
- add_x_label()
Adds an x-axis label to the plot matrix.
- add_legend()
Adds a legend to the plot matrix.
- add_data()
Adds data to the object.
- get_min_max()
Gets minimum and maximum values for x and y.
- remove_out_of_range_data()
Removes out of range data points if xlim and ylim were given.
- draw_scatter_plot()
Draws a scatter plot on the plot canvas.
- draw_line_plot()
Draws a line plot on the plot canvas.
- draw_barplot()
Draws a bar plot on the plot canvas.
- draw_barplot_braille()
Draws a bar plot with braille characters on the plot canvas.
- draw_boxplot()
Draws a box plot on the plot canvas.
- print_plot()
Assembles all plot elements and prints the plot to the console.
Public fields
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
Methods
Public methods
Method new()
Initialize object
Usage
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 )
Arguments
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.
Method initialize_plot_matrix()
Initialize the plot matrix
Usage
plotcli$initialize_plot_matrix()
Arguments
plot_width
The width of the plot
plot_height
The height of the plot
Returns
A plot matrix object
Method print()
Default print method for plotcli object
Usage
plotcli$print(...)
Arguments
...
Additional arguments passed to the print method
Returns
The plotcli object, invisibly
Method add_row()
Add a single row to the plot matrix
Usage
plotcli$add_row(bottom = FALSE)
Arguments
bottom
logical, if TRUE, add row to the bottom of the matrix, otherwise add to the top (default: FALSE)
Method add_col()
Add a single column to the plot matrix
Usage
plotcli$add_col()
Method add_borders()
Add borders to the plot matrix
Usage
plotcli$add_borders()
Method add_row_col_index()
Add row and column index to the plot matrix Add title to the plot matrix
Usage
plotcli$add_row_col_index()
Method add_title()
Usage
plotcli$add_title()
Arguments
title
character, title of the plot Add y-ticks label to the plot matrix
Method add_y_ticks()
Usage
plotcli$add_y_ticks(n_ticks = 5)
Arguments
n_ticks
numeric, number of ticks Add y-axis label to the plot matrix
Method add_y_label()
Add a y-axis label to the plot matrix
Usage
plotcli$add_y_label(y_label = self$y_label)
Arguments
y_label
character, the y-axis label to be added Add x-ticks label to the plot matrix
Method add_x_ticks()
Usage
plotcli$add_x_ticks(n_ticks = 5)
Arguments
n_ticks
numeric, number of ticks Add x-axis label to the plot matrix
Method add_x_label()
Add x-axis label to the plot matrix
Usage
plotcli$add_x_label(x_label = self$x_label)
Arguments
x_label
x label Add legend to the plot matrix
Method add_legend()
Add legend to the plot matrix Add data to the object.
Usage
plotcli$add_legend()
Method add_data()
Usage
plotcli$add_data(data)
Arguments
data
list, list with elements: x, y, type, color, braille, name Get minimum and maximum values for x and y
Method 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
Usage
plotcli$get_min_max()
Method remove_out_of_range_data()
Remove data points that are outside the specified xlim and ylim Draw a scatter plot to the plot canvas.
Usage
plotcli$remove_out_of_range_data()
Method draw_scatter_plot()
Draw a scatter plot of the specified data set on the plot canvas.
Usage
plotcli$draw_scatter_plot(set_idx)
Arguments
set_idx
numeric, the data element index to be drawn Draw a line plot to the plot canvas.
Method draw_line_plot()
Usage
plotcli$draw_line_plot(set_idx)
Arguments
set_idx
numeric, the data element index to be drawn Draw a barplot to the plot canvas.
Method draw_barplot()
Usage
plotcli$draw_barplot(set_idx)
Arguments
set_idx
numeric, the data element index to be drawn Draw a barplot to the plot canvas with braille characters.
Method draw_barplot_braille()
Usage
plotcli$draw_barplot_braille(set_idx)
Arguments
set_idx
numeric, the data element index to be drawn Draw a boxplot to the plot canvas.
Method draw_boxplot()
Usage
plotcli$draw_boxplot(set_idx)
Arguments
set_idx
numeric, the data element index to be drawn Draw colors to the canvas
Method 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
Usage
plotcli$draw_colors()
Method 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)
Usage
plotcli$draw_plot()
Method make_plot_matrix()
This function assembles all plot elements (canvas + borders + title + axes + legend) and creates the final plot matrix. Export plot matrix
Usage
plotcli$make_plot_matrix()
Method export_plot_matrix()
This function exports the plot matrix.
Usage
plotcli$export_plot_matrix()
Returns
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.
Method 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.
Usage
plotcli$print_plot()
Method merge()
Usage
plotcli$merge(other)
Arguments
other
A plotcli object to be merged with the current object.
Returns
A new plotcli object containing the combined data from both objects.
Method clone()
The objects of this class are cloneable with this method.
Usage
plotcli$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# 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()