You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"source": "# Fibonacci sequence\nfibonacci_loop <- function(n) {\n a <- 0\n b <- 1\n\n for (i in 1:n) {\n fib <- a\n cat(fib, \"\\n\")\n a <- b\n b <- fib + b\n }\n return(a)\n}\n\nfibonacci_loop(10)",
106
+
"metadata": {
107
+
"trusted": true,
108
+
"vscode": {
109
+
"languageId": "r"
110
+
}
111
+
},
112
+
"outputs": [],
113
+
"execution_count": null
114
+
},
115
+
{
116
+
"cell_type": "markdown",
117
+
"source": "## Plotting",
118
+
"metadata": {}
119
+
},
120
+
{
121
+
"cell_type": "markdown",
122
+
"source": "Some of the following R Code was pulled from https://www.statmethods.net/advgraphs/ggplot2.html, and updated to use newer `ggplot2` APIs.",
123
+
"metadata": {}
124
+
},
125
+
{
126
+
"cell_type": "code",
127
+
"source": "# ggplot2 examples\nlibrary(ggplot2)",
128
+
"metadata": {
129
+
"vscode": {
130
+
"languageId": "r"
131
+
},
132
+
"trusted": true
133
+
},
134
+
"outputs": [],
135
+
"execution_count": null
136
+
},
137
+
{
138
+
"cell_type": "code",
139
+
"source": "# create factors with value labels\nmtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),\n\tlabels=c(\"3gears\",\"4gears\",\"5gears\"))\nmtcars$am <- factor(mtcars$am,levels=c(0,1),\n\tlabels=c(\"Automatic\",\"Manual\"))\nmtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),\n labels=c(\"4cyl\",\"6cyl\",\"8cyl\"))",
140
+
"metadata": {
141
+
"vscode": {
142
+
"languageId": "r"
143
+
},
144
+
"trusted": true
145
+
},
146
+
"outputs": [],
147
+
"execution_count": null
148
+
},
149
+
{
150
+
"cell_type": "code",
151
+
"source": "# Kernel density plots for mpg\n# grouped by number of gears (indicated by color)\nggplot(mtcars, aes(x = mpg, fill = gear)) +\n geom_density(alpha = 0.5) +\n labs(\n title = \"Distribution of Gas Milage\",\n x = \"Miles Per Gallon\",\n y = \"Density\",\n fill = \"Gears\"\n )",
152
+
"metadata": {
153
+
"vscode": {
154
+
"languageId": "r"
155
+
},
156
+
"trusted": true
157
+
},
158
+
"outputs": [],
159
+
"execution_count": null
160
+
},
161
+
{
162
+
"cell_type": "code",
163
+
"source": "# Scatterplot of mpg vs. hp for each combination of gears and cylinders\n# in each facet, transmission type is represented by shape and color\nggplot(mtcars, aes(x = hp, y = mpg, shape = am, color = am)) +\n geom_point(size = 3) +\n facet_grid(gear ~ cyl) +\n labs(\n x = \"Horsepower\",\n y = \"Miles per Gallon\",\n shape = \"Transmission\",\n color = \"Transmission\"\n )",
164
+
"metadata": {
165
+
"vscode": {
166
+
"languageId": "r"
167
+
},
168
+
"trusted": true
169
+
},
170
+
"outputs": [],
171
+
"execution_count": null
172
+
},
173
+
{
174
+
"cell_type": "code",
175
+
"source": "# Separate regressions of mpg on weight for each number of cylinders\nggplot(mtcars, aes(x = wt, y = mpg, color = cyl)) +\n geom_point() +\n geom_smooth(method = \"lm\", formula = y ~ x) +\n labs(\n title = \"Regression of MPG on Weight\",\n x = \"Weight\",\n y = \"Miles per Gallon\",\n color = \"Cylinders\"\n )",
176
+
"metadata": {
177
+
"vscode": {
178
+
"languageId": "r"
179
+
},
180
+
"trusted": true
181
+
},
182
+
"outputs": [],
183
+
"execution_count": null
184
+
},
185
+
{
186
+
"cell_type": "code",
187
+
"source": "# Boxplots of mpg by number of gears\n# observations (points) are overlayed and jittered\nggplot(mtcars, aes(x = gear, y = mpg, fill = gear)) +\n geom_boxplot() +\n geom_jitter(width = 0.2) +\n labs(\n title = \"Mileage by Gear Number\",\n x = \"\",\n y = \"Miles per Gallon\",\n fill = \"Gears\"\n )",
"source": "library(crayon)\n\n# Create colorful text\nred_text <- red(\"This is red text\")\ngreen_text <- green(\"This is green text\")\nblue_text <- blue(\"This is blue text\")\nbold_text <- bold(\"This is bold text\")\nunderline_text <- underline(\"This is underlined text\")\n\ncat(red_text, \"\\n\")\ncat(green_text, \"\\n\")\ncat(blue_text, \"\\n\")\ncat(bold_text, \"\\n\")\ncat(underline_text, \"\\n\")",
221
+
"metadata": {
222
+
"trusted": true,
223
+
"vscode": {
224
+
"languageId": "r"
225
+
}
226
+
},
227
+
"outputs": [],
228
+
"execution_count": null
229
+
},
230
+
{
231
+
"cell_type": "code",
232
+
"source": "library(htmltools)\n\n# Create HMTL elements\ntitle <- tags$title(\"My HTML Page\")\nheader <- tags$h1(\"Hello there!\")\nparagraph <- tags$p(\"This is a paragraph created using htmltools.\")\nlist_items <- tags$ul(tags$li(\"Item 1\"), tags$li(\"Item 2\"), tags$li(\"Item 3\"))\n\n# Combine elements into an HTML document\nhtml_doc <- tags$html(\n tags$head(title),\n tags$body(\n header,\n paragraph,\n list_items\n )\n)\n\nprint(html_doc)",
233
+
"metadata": {
234
+
"trusted": true,
235
+
"vscode": {
236
+
"languageId": "r"
237
+
}
238
+
},
239
+
"outputs": [],
240
+
"execution_count": null
241
+
},
242
+
{
243
+
"cell_type": "code",
244
+
"source": "library(farver)\n\n# Define a color in RBG space\nrgb_color <- matrix(c(255, 0, 0), ncol = 3)\n\n# Convert RGB to HSV\nhsv_color <- convert_colour(rgb_color, \"rgb\", \"hsv\")\n\n# Convert RGB to LAB\nlab_color <- convert_colour(rgb_color, \"rgb\", \"lab\")\n\nprint(rgb_color)\nprint(hsv_color)\nprint(lab_color)",
0 commit comments