diff --git a/UsefulCode2.Rmd b/UsefulCode2.Rmd index 706224c..7973309 100644 --- a/UsefulCode2.Rmd +++ b/UsefulCode2.Rmd @@ -807,7 +807,9 @@ Separate/split df into individual dfs based on repeating value in a column df %>% mutate(trips = cumsum(IDS == 0)) %>% # create new helper col between every instance of 0 in IDS group_by(trips) %>% # group by this helper col - group_split() # spit into individual dfs + group_split() %>% # spit into individual dfs + set_names(LETTERS[1:length(.)]) %>% # create new names for each df + imap(~write_csv(.x, paste0(.y, ".csv"))) # save each object '.x' as '.y' to dir as csv based on their list names ``` diff --git a/UsefulCode2.html b/UsefulCode2.html index 8e66221..d3229b0 100644 --- a/UsefulCode2.html +++ b/UsefulCode2.html @@ -7477,7 +7477,7 @@

Colour palettes

# plot ggplot() + geom_line(data = df, aes(1:nrow(df), var1, color = var1), size = 1, show.legend = F, lineend = "round", linejoin = "round") + scale_color_gradientn(colours = colpal, aesthetics = "col") -

+

Alphanumeric hexcodes with opacity

In HTML/CSS (browser code), the format is #RRGGBBAA with @@ -7635,8 +7635,8 @@

D3

cal <- read_csv("https://raw.githubusercontent.com/rstudio/r2d3/master/vignettes/gallery/calendar/dji-latest.csv") r2d3(data = cal, d3_version = 4, container = "div", options = list(start = 2006, end = 2011), script = "calendar.js") -
- +
+

Raindrop D3 animate chart

@@ -7904,7 +7904,9 @@

dplyr basics

df %>% mutate(trips = cumsum(IDS == 0)) %>% # create new helper col between every instance of 0 in IDS group_by(trips) %>% # group by this helper col - group_split() # spit into individual dfs + group_split() %>% # spit into individual dfs + set_names(LETTERS[1:length(.)]) %>% # create new names for each df + imap(~write_csv(.x, paste0(.y, ".csv"))) # save each object '.x' as '.y' to dir as csv based on their list names

Generic functions

@@ -7984,7 +7986,8 @@

HTML/XML

code <- paste(as.character(code), collapse = "\n") -write.table(code, file = "/Users/code.html", quote = FALSE, col.names = FALSE, row.names = FALSE)
+w +te.table(code, file = "/Users/code.html", quote = FALSE, col.names = FALSE, row.names = FALSE)

Extracting multiple nodes/range of nodes at once

# require(dplyr,rvest,xml2,readr,magrittr)
 url <- "https://www.postholer.com/databook/Appalachian-Trail/3"
@@ -8034,8 +8037,8 @@ 

Interactive plots

Leaflet

-
- +
+

Interactive label options and custom tiles

require(leaflet)
 require(dplyr)
@@ -8077,15 +8080,14 @@ 

Leaflet

# map map <- gcIntermediate(latlon_matrix[1, ], latlon_matrix[2, ], n = 100, addStartEnd = T, sp = T) %>% leaflet() %>% - setView(setview[2], setview[1], -om = 3) %>% addTiles(custom_tile) %>% addCircleMarkers(mp[, "lon"], - mp[, "lat"], radius = 10, stroke = TRUE, weight = 3, opacity = opac, color = colv, fillColor = colv, - label = paste(site_names), labelOptions = marker_label_opt) %>% addPolylines(color = colv, opacity = opac) %>% - addPopups(-122.327298, 47.597131, text_label, options = popupOptions(closeButton = FALSE, textOnly = T)) %>% - addLabelOnlyMarkers(setview[2], setview[1], label = text_label, labelOptions = text_label_opt) %>% - addControl("@darwinanddavis", position = "topright") %>% addControl(title, position = "topleft", - className = "map-title") -map
+ setView(setview[2], setview[1], zoom = 3) %>% addTiles(custom_tile) %>% addCircleMarkers(mp[, "lon"], + mp[, "lat"], radius = 10, stroke = TRUE, weight = 3, opacity = opac, color = colv, fillColor = colv, + label = paste(site_names), labelOptions = marker_label_opt) %>% addPolylines(color = colv, opacity = opac) %>% + addPopups(-122.327298, 47.597131, text_label, options = popupOptions(closeButton = FALSE, textOnly = T)) %>% + addLabelOnlyMarkers(setview[2], setview[1], label = text_label, labelOptions = text_label_opt) %>% + addControl("@darwinanddavis", position = "topright") %>% addControl(title, position = "topleft", + className = "map-title") +map

Add multiple layers at once (uses loop)

# https://stackoverflow.com/questions/38701359/grouped-layer-control-in-leaflet-r
@@ -8548,8 +8550,8 @@ 

plotly

time(), 4)) sm %>% plot_ly(x = sm$time, y = sm$price, color = sm$index)
-
- +
+

Strings