plotcli-py 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. CLAUDE.md +51 -0
  2. LICENSE +21 -0
  3. PKG-INFO +358 -0
  4. README.md +340 -0
  5. main.py +6 -0
  6. plotcli-original/.Rbuildignore +18 -0
  7. plotcli-original/.github/workflows/deploy_docs.yml +43 -0
  8. plotcli-original/.gitignore +46 -0
  9. plotcli-original/DESCRIPTION +25 -0
  10. plotcli-original/NAMESPACE +60 -0
  11. plotcli-original/NEWS.md +112 -0
  12. plotcli-original/R/ascii_escape.r +13 -0
  13. plotcli-original/R/canvas.r +586 -0
  14. plotcli-original/R/class_functions.r +114 -0
  15. plotcli-original/R/geom_registry.r +1376 -0
  16. plotcli-original/R/ggplotcli.r +234 -0
  17. plotcli-original/R/ggplotcli_helpers.r +1099 -0
  18. plotcli-original/R/helper_functions.r +351 -0
  19. plotcli-original/R/plotcli.r +963 -0
  20. plotcli-original/R/plotcli_grid.r +1 -0
  21. plotcli-original/R/plotcli_wrappers.r +416 -0
  22. plotcli-original/R/zzz.r +15 -0
  23. plotcli-original/README.md +192 -0
  24. plotcli-original/docs/ascii.png +0 -0
  25. plotcli-original/docs/bar.png +0 -0
  26. plotcli-original/docs/block.png +0 -0
  27. plotcli-original/docs/boxplot.png +0 -0
  28. plotcli-original/docs/density.png +0 -0
  29. plotcli-original/docs/facet.png +0 -0
  30. plotcli-original/docs/facet_grid.png +0 -0
  31. plotcli-original/docs/generate_png.sh +137 -0
  32. plotcli-original/docs/heatmap.png +0 -0
  33. plotcli-original/docs/histogram.png +0 -0
  34. plotcli-original/docs/line.png +0 -0
  35. plotcli-original/docs/noborder.png +0 -0
  36. plotcli-original/docs/scatter.png +0 -0
  37. plotcli-original/docs/showcase.R +182 -0
  38. plotcli-original/inst/doc/ggplotcli.R +231 -0
  39. plotcli-original/inst/doc/ggplotcli.Rmd +329 -0
  40. plotcli-original/inst/doc/ggplotcli.html +1078 -0
  41. plotcli-original/inst/doc/plotcli_class.R +98 -0
  42. plotcli-original/inst/doc/plotcli_class.Rmd +121 -0
  43. plotcli-original/inst/doc/plotcli_class.html +564 -0
  44. plotcli-original/inst/doc/plotcli_wrappers.R +35 -0
  45. plotcli-original/inst/doc/plotcli_wrappers.Rmd +62 -0
  46. plotcli-original/inst/doc/plotcli_wrappers.html +546 -0
  47. plotcli-original/man/AsciiCanvas.Rd +116 -0
  48. plotcli-original/man/BlockCanvas.Rd +132 -0
  49. plotcli-original/man/BrailleCanvas.Rd +146 -0
  50. plotcli-original/man/Canvas.Rd +492 -0
  51. plotcli-original/man/GeomRegistry.Rd +9 -0
  52. plotcli-original/man/add_legend_to_output.Rd +12 -0
  53. plotcli-original/man/braille_dot_bit.Rd +29 -0
  54. plotcli-original/man/braille_set_dot.Rd +21 -0
  55. plotcli-original/man/bresenham.Rd +27 -0
  56. plotcli-original/man/build_plot_output.Rd +28 -0
  57. plotcli-original/man/build_plot_output_v2.Rd +41 -0
  58. plotcli-original/man/cat_plot_matrix.Rd +17 -0
  59. plotcli-original/man/cbind.plotcli.Rd +19 -0
  60. plotcli-original/man/cbind_plots.Rd +17 -0
  61. plotcli-original/man/color_to_term.Rd +18 -0
  62. plotcli-original/man/create_canvas.Rd +21 -0
  63. plotcli-original/man/create_panel_scales.Rd +29 -0
  64. plotcli-original/man/create_scales.Rd +27 -0
  65. plotcli-original/man/dot-geom_registry.Rd +16 -0
  66. plotcli-original/man/draw_border.Rd +12 -0
  67. plotcli-original/man/draw_grid.Rd +12 -0
  68. plotcli-original/man/extract_legend_info.Rd +12 -0
  69. plotcli-original/man/extract_plot_labels.Rd +12 -0
  70. plotcli-original/man/extract_plot_style.Rd +12 -0
  71. plotcli-original/man/format_axis_label.Rd +18 -0
  72. plotcli-original/man/format_four_chars.Rd +21 -0
  73. plotcli-original/man/geom_area_handler.Rd +12 -0
  74. plotcli-original/man/geom_bar_handler.Rd +12 -0
  75. plotcli-original/man/geom_boxplot_handler.Rd +13 -0
  76. plotcli-original/man/geom_density_handler.Rd +12 -0
  77. plotcli-original/man/geom_histogram_handler.Rd +12 -0
  78. plotcli-original/man/geom_hline_handler.Rd +12 -0
  79. plotcli-original/man/geom_line_handler.Rd +12 -0
  80. plotcli-original/man/geom_path_handler.Rd +12 -0
  81. plotcli-original/man/geom_point_handler.Rd +12 -0
  82. plotcli-original/man/geom_rect_handler.Rd +12 -0
  83. plotcli-original/man/geom_segment_handler.Rd +12 -0
  84. plotcli-original/man/geom_smooth_handler.Rd +12 -0
  85. plotcli-original/man/geom_text_handler.Rd +12 -0
  86. plotcli-original/man/geom_vline_handler.Rd +12 -0
  87. plotcli-original/man/get_color_hue.Rd +18 -0
  88. plotcli-original/man/get_data_subset.Rd +23 -0
  89. plotcli-original/man/get_facet_info.Rd +18 -0
  90. plotcli-original/man/get_geom_handler.Rd +17 -0
  91. plotcli-original/man/get_term_colors.Rd +21 -0
  92. plotcli-original/man/ggplotcli.Rd +83 -0
  93. plotcli-original/man/init_color_mapping.Rd +15 -0
  94. plotcli-original/man/is_braille.Rd +20 -0
  95. plotcli-original/man/is_geom_registered.Rd +17 -0
  96. plotcli-original/man/list_registered_geoms.Rd +14 -0
  97. plotcli-original/man/make_colored.Rd +23 -0
  98. plotcli-original/man/make_unique_names.Rd +20 -0
  99. plotcli-original/man/normalize_data.Rd +27 -0
  100. plotcli-original/man/pclib.Rd +48 -0
  101. plotcli-original/man/pclibx.Rd +46 -0
  102. plotcli-original/man/pclid.Rd +44 -0
  103. plotcli-original/man/pclih.Rd +50 -0
  104. plotcli-original/man/pclil.Rd +48 -0
  105. plotcli-original/man/pclis.Rd +48 -0
  106. plotcli-original/man/pixel_to_braille.Rd +23 -0
  107. plotcli-original/man/plotcli.Rd +598 -0
  108. plotcli-original/man/plotcli_bar.Rd +48 -0
  109. plotcli-original/man/plotcli_box.Rd +46 -0
  110. plotcli-original/man/plotcli_density.Rd +44 -0
  111. plotcli-original/man/plotcli_histogram.Rd +50 -0
  112. plotcli-original/man/plotcli_line.Rd +48 -0
  113. plotcli-original/man/plotcli_options.Rd +18 -0
  114. plotcli-original/man/plotcli_scatter.Rd +48 -0
  115. plotcli-original/man/plus-.plotcli.Rd +19 -0
  116. plotcli-original/man/rbind.plotcli.Rd +19 -0
  117. plotcli-original/man/rbind_plots.Rd +17 -0
  118. plotcli-original/man/register_geom.Rd +21 -0
  119. plotcli-original/man/remove_color_codes.Rd +21 -0
  120. plotcli-original/man/render_faceted_plot.Rd +25 -0
  121. plotcli-original/man/render_single_panel.Rd +12 -0
  122. plotcli-original/man/safe_aes_name.Rd +18 -0
  123. plotcli-original/tests/testthat/test-new-geoms.R +136 -0
  124. plotcli-original/tests/testthat/test-plotcli.R +69 -0
  125. plotcli-original/tests/testthat.R +4 -0
  126. plotcli-original/vignettes/ggplotcli.Rmd +329 -0
  127. plotcli-original/vignettes/plotcli_class.R +98 -0
  128. plotcli-original/vignettes/plotcli_class.Rmd +121 -0
  129. plotcli-original/vignettes/plotcli_wrappers.R +35 -0
  130. plotcli-original/vignettes/plotcli_wrappers.Rmd +62 -0
  131. plotcli.egg-info/PKG-INFO +11 -0
  132. plotcli.egg-info/SOURCES.txt +7 -0
  133. plotcli.egg-info/dependency_links.txt +1 -0
  134. plotcli.egg-info/entry_points.txt +3 -0
  135. plotcli.egg-info/top_level.txt +1 -0
  136. plotcli.py +978 -0
  137. plotcli_py-0.1.0.dist-info/METADATA +358 -0
  138. plotcli_py-0.1.0.dist-info/RECORD +143 -0
  139. plotcli_py-0.1.0.dist-info/WHEEL +4 -0
  140. plotcli_py-0.1.0.dist-info/entry_points.txt +2 -0
  141. plotcli_py-0.1.0.dist-info/licenses/LICENSE +21 -0
  142. pyproject.toml +31 -0
  143. uv.lock +8 -0
@@ -0,0 +1,137 @@
1
+ #!/bin/bash
2
+ # generate_png.sh - Generate PNG images from plotcli terminal output
3
+ #
4
+ # This script captures ANSI-colored terminal output from R/plotcli and converts
5
+ # it to PNG images with a nice terminal theme (Solarized Dark).
6
+ #
7
+ # Requirements:
8
+ # - R with plotcli, ggplot2, dplyr installed
9
+ # - Python 3 with ansi2html: pip install ansi2html
10
+ # - Chromium or Google Chrome browser
11
+ #
12
+ # Usage:
13
+ # ./generate_png.sh input.R output.png [width] [height]
14
+ #
15
+ # Example:
16
+ # # Create a simple R script
17
+ # echo 'library(plotcli); library(ggplot2)
18
+ # p <- ggplot(mtcars, aes(x=wt, y=mpg, color=factor(cyl))) + geom_point()
19
+ # ggplotcli(p, width=70, height=18)' > myplot.R
20
+ #
21
+ # # Generate PNG
22
+ # ./generate_png.sh myplot.R myplot.png
23
+ #
24
+ # # With custom dimensions (default: 900x550)
25
+ # ./generate_png.sh myplot.R myplot.png 1000 600
26
+
27
+ set -e
28
+
29
+ # Check arguments
30
+ if [ $# -lt 2 ]; then
31
+ echo "Usage: $0 <input.R> <output.png> [width] [height]"
32
+ echo ""
33
+ echo "Example:"
34
+ echo " $0 myplot.R myplot.png"
35
+ echo " $0 myplot.R myplot.png 1000 600"
36
+ exit 1
37
+ fi
38
+
39
+ INPUT_R="$1"
40
+ OUTPUT_PNG="$2"
41
+ WIDTH="${3:-900}"
42
+ HEIGHT="${4:-550}"
43
+
44
+ # Check if input file exists
45
+ if [ ! -f "$INPUT_R" ]; then
46
+ echo "Error: Input file '$INPUT_R' not found"
47
+ exit 1
48
+ fi
49
+
50
+ # Check dependencies
51
+ if ! command -v Rscript &> /dev/null; then
52
+ echo "Error: Rscript not found. Please install R."
53
+ exit 1
54
+ fi
55
+
56
+ if ! python3 -c "import ansi2html" &> /dev/null; then
57
+ echo "Error: ansi2html not found. Install with: pip install ansi2html"
58
+ exit 1
59
+ fi
60
+
61
+ # Find chromium or chrome
62
+ CHROME=""
63
+ for cmd in chromium chromium-browser google-chrome google-chrome-stable; do
64
+ if command -v "$cmd" &> /dev/null; then
65
+ CHROME="$cmd"
66
+ break
67
+ fi
68
+ done
69
+
70
+ if [ -z "$CHROME" ]; then
71
+ echo "Error: Chromium or Google Chrome not found"
72
+ exit 1
73
+ fi
74
+
75
+ # Create temp files
76
+ TEMP_DIR=$(mktemp -d)
77
+ TEMP_HTML="$TEMP_DIR/plot.html"
78
+ TEMP_ANSI="$TEMP_DIR/plot.ansi"
79
+
80
+ # Cleanup on exit
81
+ cleanup() {
82
+ rm -rf "$TEMP_DIR"
83
+ }
84
+ trap cleanup EXIT
85
+
86
+ # Run R script and capture ANSI output
87
+ echo "Running R script..."
88
+ LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 Rscript "$INPUT_R" 2>/dev/null > "$TEMP_ANSI"
89
+
90
+ # Convert ANSI to HTML with inline styles
91
+ echo "Converting to HTML..."
92
+ ANSI_CONTENT=$(cat "$TEMP_ANSI" | python3 -m ansi2html --inline)
93
+
94
+ # Create themed HTML
95
+ cat > "$TEMP_HTML" << EOF
96
+ <!DOCTYPE html>
97
+ <html>
98
+ <head>
99
+ <style>
100
+ * { margin: 0; padding: 0; box-sizing: border-box; }
101
+ html, body {
102
+ background: #073642;
103
+ }
104
+ .terminal {
105
+ background: #073642;
106
+ padding: 10px 15px;
107
+ font-family: "DejaVu Sans Mono", "Liberation Mono", "Consolas", monospace;
108
+ font-size: 13px;
109
+ line-height: 1.35;
110
+ color: #839496;
111
+ white-space: pre;
112
+ }
113
+ /* Solarized Dark ANSI color overrides */
114
+ .terminal span[style*="color: #aa0000"] { color: #dc322f !important; }
115
+ .terminal span[style*="color: #00aa00"] { color: #859900 !important; }
116
+ .terminal span[style*="color: #aa5500"] { color: #b58900 !important; }
117
+ .terminal span[style*="color: #0000aa"] { color: #268bd2 !important; }
118
+ .terminal span[style*="color: #aa00aa"] { color: #d33682 !important; }
119
+ .terminal span[style*="color: #00aaaa"] { color: #2aa198 !important; }
120
+ .terminal span[style*="color: #E850A8"] { color: #6c71c4 !important; }
121
+ </style>
122
+ </head>
123
+ <body>
124
+ <div class="terminal">
125
+ $ANSI_CONTENT
126
+ </div>
127
+ </body>
128
+ </html>
129
+ EOF
130
+
131
+ # Convert HTML to PNG using headless Chrome
132
+ echo "Generating PNG..."
133
+ "$CHROME" --headless --disable-gpu --screenshot="$OUTPUT_PNG" \
134
+ --window-size="${WIDTH},${HEIGHT}" \
135
+ "file://$TEMP_HTML" 2>/dev/null
136
+
137
+ echo "Done! Output saved to: $OUTPUT_PNG"
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env Rscript
2
+ # plotcli Showcase
3
+ # Run this script to see all the features of plotcli in action
4
+ # Usage: Rscript docs/showcase.R
5
+
6
+ library(plotcli)
7
+ library(ggplot2)
8
+ library(dplyr)
9
+
10
+ cat("\n")
11
+ cat("========================================================================\n")
12
+ cat(" plotcli Feature Showcase\n")
13
+ cat("========================================================================\n\n")
14
+
15
+ # -----------------------------------------------------------------------------
16
+ cat("1. SCATTER PLOT WITH LEGEND\n")
17
+ cat("------------------------------------------------------------------------\n\n")
18
+
19
+ p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
20
+ geom_point(size = 3) +
21
+ labs(title = "MPG vs Weight by Cylinders",
22
+ x = "Weight (1000 lbs)", y = "Miles per Gallon",
23
+ color = "Cylinders") +
24
+ theme_bw()
25
+ ggplotcli(p, width = 75, height = 20)
26
+
27
+ cat("\n")
28
+
29
+ # -----------------------------------------------------------------------------
30
+ cat("2. DENSITY PLOT WITH FILL COLORS\n")
31
+ cat("------------------------------------------------------------------------\n\n")
32
+
33
+ p <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
34
+ geom_density(alpha = 0.7) +
35
+ labs(title = "Iris Sepal Length Distribution",
36
+ x = "Sepal Length (cm)", y = "Density") +
37
+ theme_bw()
38
+ ggplotcli(p, width = 75, height = 18)
39
+
40
+ cat("\n")
41
+
42
+ # -----------------------------------------------------------------------------
43
+ cat("3. BOXPLOT WITH OUTLIERS\n")
44
+ cat("------------------------------------------------------------------------\n\n")
45
+
46
+ set.seed(42)
47
+ boxplot_data <- data.frame(
48
+ category = rep(c("Group A", "Group B", "Group C", "Group D", "Group E"), each = 50),
49
+ value = c(
50
+ rnorm(50, mean = 25, sd = 5),
51
+ rnorm(50, mean = 35, sd = 6),
52
+ rnorm(50, mean = 20, sd = 4),
53
+ rnorm(50, mean = 40, sd = 7),
54
+ rnorm(50, mean = 30, sd = 5)
55
+ )
56
+ )
57
+
58
+ p <- ggplot(boxplot_data, aes(x = category, y = value, fill = category)) +
59
+ geom_boxplot() +
60
+ labs(title = "Distribution Comparison by Group",
61
+ x = "Category", y = "Value") +
62
+ theme_bw() +
63
+ theme(legend.position = "none")
64
+ ggplotcli(p, width = 75, height = 22, boxplot_style = "ascii")
65
+
66
+ cat("\n")
67
+
68
+ # -----------------------------------------------------------------------------
69
+ cat("4. HEATMAP (CORRELATION MATRIX)\n")
70
+ cat("------------------------------------------------------------------------\n\n")
71
+
72
+ cor_data <- cor(mtcars[, c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec")]) %>%
73
+ as.data.frame() %>%
74
+ tibble::rownames_to_column("var1") %>%
75
+ tidyr::pivot_longer(-var1, names_to = "var2", values_to = "correlation")
76
+
77
+ p <- ggplot(cor_data, aes(x = var1, y = var2, fill = correlation)) +
78
+ geom_tile() +
79
+ scale_fill_gradient2(low = "blue", mid = "white", high = "red",
80
+ midpoint = 0, limits = c(-1, 1)) +
81
+ labs(title = "Correlation Heatmap - mtcars") +
82
+ theme_minimal()
83
+ ggplotcli(p, width = 70, height = 20)
84
+
85
+ cat("\n")
86
+
87
+ # -----------------------------------------------------------------------------
88
+ cat("5. FACETED PLOT (facet_wrap)\n")
89
+ cat("------------------------------------------------------------------------\n\n")
90
+
91
+ p <- ggplot(mpg, aes(x = displ, y = hwy, color = drv)) +
92
+ geom_point(size = 2) +
93
+ facet_wrap(~cyl, ncol = 2) +
94
+ labs(title = "Highway MPG vs Engine Displacement",
95
+ subtitle = "Faceted by Cylinder Count",
96
+ x = "Displacement (L)", y = "Highway MPG",
97
+ color = "Drive") +
98
+ theme_bw()
99
+ ggplotcli(p, width = 85, height = 26)
100
+
101
+ cat("\n")
102
+
103
+ # -----------------------------------------------------------------------------
104
+ cat("6. LINE CHART WITH SMOOTHING\n")
105
+ cat("------------------------------------------------------------------------\n\n")
106
+
107
+ econ <- economics %>% filter(date >= "1990-01-01", date <= "2015-01-01")
108
+ p <- ggplot(econ, aes(x = date, y = unemploy/1000)) +
109
+ geom_line(color = "steelblue", linewidth = 1) +
110
+ geom_smooth(color = "red", se = FALSE, method = "loess", span = 0.3) +
111
+ labs(title = "US Unemployment Over Time",
112
+ subtitle = "Blue: actual data, Red: smoothed trend",
113
+ x = "Year", y = "Unemployed (millions)") +
114
+ theme_bw()
115
+ ggplotcli(p, width = 80, height = 16)
116
+
117
+ cat("\n")
118
+
119
+ # -----------------------------------------------------------------------------
120
+ cat("7. BAR CHART (GROUPED)\n")
121
+ cat("------------------------------------------------------------------------\n\n")
122
+
123
+ p <- ggplot(mpg, aes(x = class, fill = drv)) +
124
+ geom_bar(position = "dodge") +
125
+ labs(title = "Vehicle Classes by Drive Type",
126
+ x = "Vehicle Class", y = "Count",
127
+ fill = "Drive") +
128
+ theme_bw()
129
+ ggplotcli(p, width = 80, height = 16)
130
+
131
+ cat("\n")
132
+
133
+ # -----------------------------------------------------------------------------
134
+ cat("8. HISTOGRAM WITH DENSITY OVERLAY\n")
135
+ cat("------------------------------------------------------------------------\n\n")
136
+
137
+ p <- ggplot(mtcars, aes(x = mpg)) +
138
+ geom_histogram(aes(y = after_stat(density)), bins = 12,
139
+ fill = "steelblue", color = "white") +
140
+ geom_density(color = "red", linewidth = 1) +
141
+ labs(title = "Distribution of MPG",
142
+ x = "Miles per Gallon", y = "Density") +
143
+ theme_bw()
144
+ ggplotcli(p, width = 70, height = 16)
145
+
146
+ cat("\n")
147
+
148
+ # -----------------------------------------------------------------------------
149
+ cat("9. CANVAS TYPE COMPARISON\n")
150
+ cat("------------------------------------------------------------------------\n\n")
151
+
152
+ base_plot <- ggplot(mtcars, aes(x = wt, y = mpg)) +
153
+ geom_point(color = "blue") +
154
+ labs(title = "Canvas Comparison") +
155
+ theme_bw()
156
+
157
+ cat("BRAILLE canvas (high resolution):\n\n")
158
+ ggplotcli(base_plot, width = 50, height = 12, canvas_type = "braille")
159
+
160
+ cat("\nBLOCK canvas (medium resolution):\n\n")
161
+ ggplotcli(base_plot, width = 50, height = 12, canvas_type = "block")
162
+
163
+ cat("\nASCII canvas (maximum compatibility):\n\n")
164
+ ggplotcli(base_plot, width = 50, height = 12, canvas_type = "ascii")
165
+
166
+ cat("\n")
167
+
168
+ # -----------------------------------------------------------------------------
169
+ cat("10. FACET GRID (2D FACETING)\n")
170
+ cat("------------------------------------------------------------------------\n\n")
171
+
172
+ p <- ggplot(mpg %>% filter(cyl %in% c(4, 6, 8)), aes(x = displ, y = hwy)) +
173
+ geom_point(color = "steelblue") +
174
+ facet_grid(drv ~ cyl) +
175
+ labs(title = "Facet Grid: Drive Type vs Cylinders") +
176
+ theme_bw()
177
+ ggplotcli(p, width = 90, height = 28)
178
+
179
+ cat("\n")
180
+ cat("========================================================================\n")
181
+ cat(" End of Showcase\n")
182
+ cat("========================================================================\n\n")
@@ -0,0 +1,231 @@
1
+ ## ----setup, include = FALSE---------------------------------------------------
2
+ knitr::opts_chunk$set(
3
+ collapse = TRUE,
4
+ comment = "#>"
5
+ )
6
+
7
+
8
+ ## -----------------------------------------------------------------------------
9
+ library(plotcli)
10
+ library(ggplot2)
11
+
12
+ # Create a ggplot
13
+ p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
14
+ geom_point() +
15
+ labs(title = "MPG vs Weight by Cylinders")
16
+
17
+ # Render in terminal
18
+ ggplotcli(p, width = 60, height = 16)
19
+
20
+
21
+ ## -----------------------------------------------------------------------------
22
+ p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
23
+ geom_point() +
24
+ labs(title = "Iris: Sepal Dimensions by Species")
25
+ ggplotcli(p, width = 60, height = 16)
26
+
27
+
28
+ ## -----------------------------------------------------------------------------
29
+ # Multiple colored lines
30
+ df <- data.frame(
31
+ x = rep(1:30, 2),
32
+ y = c(sin(1:30/4) * 10, cos(1:30/4) * 10),
33
+ type = rep(c("sin", "cos"), each = 30)
34
+ )
35
+ p <- ggplot(df, aes(x, y, color = type)) +
36
+ geom_line() +
37
+ labs(title = "Sine and Cosine Waves")
38
+ ggplotcli(p, width = 60, height = 12)
39
+
40
+
41
+ ## -----------------------------------------------------------------------------
42
+ p <- ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) +
43
+ geom_histogram(bins = 10, position = "dodge") +
44
+ labs(title = "MPG Distribution by Cylinders")
45
+ ggplotcli(p, width = 60, height = 12)
46
+
47
+
48
+ ## -----------------------------------------------------------------------------
49
+ p <- ggplot(mtcars, aes(x = mpg, color = factor(cyl))) +
50
+ geom_density() +
51
+ labs(title = "MPG Density by Cylinders")
52
+ ggplotcli(p, width = 60, height = 12)
53
+
54
+
55
+ ## -----------------------------------------------------------------------------
56
+ df <- data.frame(
57
+ category = c("A", "B", "C", "D", "E", "F"),
58
+ value = c(25, 45, 30, 60, 35, 50)
59
+ )
60
+ p <- ggplot(df, aes(x = category, y = value, fill = category)) +
61
+ geom_col() +
62
+ labs(title = "Category Values")
63
+ ggplotcli(p, width = 60, height = 12)
64
+
65
+
66
+ ## -----------------------------------------------------------------------------
67
+ set.seed(42)
68
+ df <- data.frame(
69
+ group = factor(rep(paste0("Group ", 1:6), each = 50)),
70
+ value = c(rnorm(50, 10, 3), rnorm(50, 5, 2), rnorm(50, 8, 4),
71
+ rnorm(50, 6, 2), rnorm(50, 12, 3), rnorm(50, 7, 2))
72
+ )
73
+ p <- ggplot(df, aes(x = group, y = value, fill = group)) +
74
+ geom_boxplot() +
75
+ labs(title = "Boxplot Colored by Group", y = "Value", x = "Group")
76
+ ggplotcli(p, width = 80, height = 20, boxplot_style = "ascii")
77
+
78
+
79
+ ## -----------------------------------------------------------------------------
80
+ ggplotcli(p, width = 80, height = 20, boxplot_style = "braille")
81
+
82
+
83
+ ## -----------------------------------------------------------------------------
84
+ # Histogram with density overlay
85
+ p <- ggplot(mtcars, aes(x = mpg)) +
86
+ geom_histogram(aes(y = after_stat(density)), bins = 10, fill = "gray") +
87
+ geom_density(color = "red") +
88
+ labs(title = "Histogram with Density Overlay")
89
+ ggplotcli(p, width = 60, height = 12)
90
+
91
+
92
+ ## -----------------------------------------------------------------------------
93
+ # Points with smooth line
94
+ p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
95
+ geom_point(color = "gray") +
96
+ geom_smooth(method = "loess", color = "red") +
97
+ labs(title = "Scatter with LOESS Smooth")
98
+ suppressMessages(ggplotcli(p, width = 60, height = 12))
99
+
100
+
101
+ ## -----------------------------------------------------------------------------
102
+ mtcars$cyl_fac <- factor(mtcars$cyl)
103
+ p <- ggplot(mtcars, aes(x = wt, y = mpg, color = cyl_fac)) +
104
+ geom_point() +
105
+ facet_wrap(~cyl_fac) +
106
+ labs(title = "MPG vs Weight: Faceted by Cylinders")
107
+ ggplotcli(p, width = 75, height = 16)
108
+
109
+
110
+ ## -----------------------------------------------------------------------------
111
+ p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(gear))) +
112
+ geom_point() +
113
+ facet_grid(am ~ cyl) +
114
+ labs(title = "MPG: AM (rows) x Cylinders (cols)")
115
+ ggplotcli(p, width = 80, height = 20)
116
+
117
+
118
+ ## -----------------------------------------------------------------------------
119
+ p <- ggplot(mtcars, aes(x = hp, y = qsec)) +
120
+ geom_point(color = "cyan") +
121
+ labs(title = "Quarter Mile Time vs HP")
122
+
123
+ # With border
124
+ ggplotcli(p, width = 55, height = 12, border = TRUE)
125
+
126
+ # With grid
127
+ ggplotcli(p, width = 55, height = 12, grid = "major")
128
+
129
+ # Both
130
+ ggplotcli(p, width = 55, height = 12, border = TRUE, grid = "major")
131
+
132
+
133
+ ## -----------------------------------------------------------------------------
134
+ p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
135
+ geom_point(color = "blue") +
136
+ labs(title = "theme_bw() - Grid + Border")
137
+
138
+ # theme_bw has both grid and border
139
+ ggplotcli(p + theme_bw(), width = 60, height = 14, border = "auto", grid = "auto")
140
+
141
+ # theme_classic has border but no grid
142
+ ggplotcli(p + theme_classic() + labs(title = "theme_classic() - Border Only"),
143
+ width = 60, height = 14, border = "auto", grid = "auto")
144
+
145
+
146
+ ## -----------------------------------------------------------------------------
147
+ wave <- ggplot(data.frame(x = 1:25, y = sin(1:25/4)*8), aes(x, y)) +
148
+ geom_line(color = "green")
149
+
150
+ # Braille (highest resolution - 2x4 dots per character)
151
+ ggplotcli(wave + labs(title = "Braille Canvas (highest resolution)"),
152
+ width = 50, height = 8, canvas_type = "braille")
153
+
154
+ # Block (medium resolution - uses block characters)
155
+ ggplotcli(wave + labs(title = "Block Canvas (medium resolution)"),
156
+ width = 50, height = 8, canvas_type = "block")
157
+
158
+ # ASCII (basic, most compatible)
159
+ ggplotcli(wave + labs(title = "ASCII Canvas (most compatible)"),
160
+ width = 50, height = 8, canvas_type = "ascii")
161
+
162
+
163
+ ## -----------------------------------------------------------------------------
164
+ set.seed(123)
165
+ df <- data.frame(
166
+ group = factor(rep(paste0("G", 1:8), each = 30)),
167
+ value = unlist(lapply(1:8, function(i) rnorm(30, mean = i * 2, sd = 1.5)))
168
+ )
169
+ p <- ggplot(df, aes(x = group, y = value, fill = group)) +
170
+ geom_boxplot() +
171
+ labs(title = "8 Groups with Optimized Color Distribution")
172
+ ggplotcli(p, width = 85, height = 18, boxplot_style = "ascii")
173
+
174
+
175
+ ## -----------------------------------------------------------------------------
176
+ set.seed(42)
177
+ df <- data.frame(
178
+ treatment = factor(rep(c("Control", "Drug A", "Drug B"), each = 60)),
179
+ timepoint = factor(rep(rep(c("Baseline", "Week 4", "Week 8"), each = 20), 3)),
180
+ response = c(
181
+ rnorm(20, 50, 10), rnorm(20, 52, 10), rnorm(20, 51, 10), # Control
182
+ rnorm(20, 50, 10), rnorm(20, 65, 12), rnorm(20, 70, 11), # Drug A
183
+ rnorm(20, 50, 10), rnorm(20, 58, 11), rnorm(20, 62, 10) # Drug B
184
+ )
185
+ )
186
+
187
+ p <- ggplot(df, aes(x = timepoint, y = response)) +
188
+ geom_boxplot(aes(fill = treatment)) +
189
+ labs(title = "Treatment Response Over Time",
190
+ subtitle = "Faceted by treatment group",
191
+ x = "Timepoint", y = "Response") +
192
+ theme_bw()
193
+
194
+ ggplotcli(p, width = 100, height = 22, boxplot_style = "ascii")
195
+
196
+
197
+ ## -----------------------------------------------------------------------------
198
+ # Simulated experiment data
199
+ set.seed(123)
200
+ x <- seq(0, 10, length.out = 50)
201
+ df <- data.frame(
202
+ x = rep(x, 3),
203
+ y = c(
204
+ 2 * x + rnorm(50, 0, 1.5),
205
+ 1.5 * x + 3 + rnorm(50, 0, 1.2),
206
+ x^1.2 + rnorm(50, 0, 1)
207
+ ),
208
+ group = rep(c("Linear", "Offset", "Power"), each = 50)
209
+ )
210
+
211
+ p <- ggplot(df, aes(x = x, y = y, color = group)) +
212
+ geom_point(alpha = 0.6) +
213
+ geom_smooth(method = "loess", se = FALSE) +
214
+ labs(title = "Multi-Group Regression Analysis",
215
+ subtitle = "Points with LOESS smoothing",
216
+ x = "Predictor", y = "Response") +
217
+ theme_minimal()
218
+
219
+ suppressMessages(ggplotcli(p, width = 70, height = 18))
220
+
221
+
222
+ ## -----------------------------------------------------------------------------
223
+ p <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
224
+ geom_point() +
225
+ facet_wrap(~Species) +
226
+ labs(title = "Iris Dataset: Sepal vs Petal Length",
227
+ subtitle = "Faceted by species with color legend") +
228
+ theme_bw()
229
+
230
+ ggplotcli(p, width = 80, height = 16)
231
+