Skip to content

Instantly share code, notes, and snippets.

library(tidyverse)
library(ggdebug)
calls_use_method <- function(expr) {
if (rlang::is_call(expr, "UseMethod")) {
TRUE
} else if (is.call(expr)) {
any(map_lgl(expr, calls_use_method))
} else {
FALSE
library(ggplot2)
library(dplyr)
library(tibble)
SortingRange <- ggproto(
"SortingRange", ggplot2:::Range,
counted_range = tibble(value = character(0), n = integer(0)),
train = function(self, x, ...) {
new_counted_range <- tibble(value = x) %>%
# remotes::install_github("paleolimbot/ggplot2@2b2f4fb9ad8ada3c2f614185441db1d790b8db2e")
library(ggplot2)
ggplot(mpg, aes(class, hwy)) +
geom_point() +
guides(
y = guide_axis(order = 2),
y.sec = guide_axis(position = "left", order = 2, angle = 45)
)
# remotes::install_github("paleolimbot/ggplot2@2b2f4fb9ad8ada3c2f614185441db1d790b8db2e")
library(ggplot2)
# plot with overlapping text
p <- ggplot(mpg, aes(cty * 100, hwy * 100)) +
geom_point() +
facet_wrap(vars(class))
# axis guides can now be customized!
library(ggplot2)
symmetric_range <- function(range) {
max_abs <- max(abs(range))
c(-max_abs, max_abs)
}
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
library(ggplot2)
library(ggdebug) # remotes::install_github("paleolimbot/ggdebug")
# the classic ggplot!
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy, colour = class))
# ...is really this:
p <- ggplot(mpg) +
library(tidyverse)
# best case: your data is already in the right form
perfect_data <- tibble(
day_in_year = c(1, 101, 201, 1, 101, 201, 1, 101, 201),
depth = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
temp = c(15, 16, 17, 14, 15, 16, 13, 14, 15)
)
ggplot(perfect_data, aes(x = day_in_year, y = depth, fill = temp)) +
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
library(tidyverse)
files <- crossing(
tibble(station_id = 42583, timeframe = 1),
tibble(year = 2018:2019),
tibble(month = 1:12)
) %>%
mutate(
url = glue::glue(
"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&Month={month}&stationID={station_id}&submit=Download%20Data&timeframe=1&Year={year}"