This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DF1 <- structure(list(Date = structure(c(1451865600, 1451865600, 1451865600, | |
1451865600, 1452988800, 1455148800, 1455148800, 1455494400, 1455494400, | |
1455494400, 1455494400, 1455667200, 1455667200, 1455667200, 1457308800, | |
1457308800, 1457308800, 1457308800, 1457827200, 1457827200, 1458604800, | |
1458604800, 1458604800, 1458604800, 1458691200, 1458691200, 1458691200, | |
1458691200, 1463875200, 1463875200, 1463875200, 1468281600, 1468281600, | |
1468281600, 1468281600, 1473465600, 1476316800, 1476316800, 1476316800, | |
1476316800, 1482192000, 1482192000, 1482192000, 1482192000), class = c("POSIXct", | |
"POSIXt"), tzone = "UTC"), Salesman = c("Edyta", "Edyta", "Edyta", | |
"Edyta", "Ewa", "Lena", "Lena", "Michal", "Michal", "Michal", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr, warn.conflicts = FALSE) | |
runs_id <- function(...) { | |
uq <- interaction(..., drop = TRUE) | |
runs <- rle(as.character(uq))$lengths | |
rep(seq_along(runs), times = runs) | |
} | |
mtcars %>% | |
select(cyl, am) %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggtrace) | |
library(magick) | |
# Plot code from https://ggplot2-book.org/internals.html | |
p <- ggplot(mpg, aes(displ, hwy, color = drv)) + | |
geom_point(position = position_jitter(seed = 2022)) + | |
geom_smooth(method = "lm", formula = y ~ x) + | |
facet_wrap(vars(year)) + | |
ggtitle("A plot for expository purposes") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggtrace) | |
polar_plot <- ggplot(mtcars ,aes(hp, mpg)) + | |
geom_point() + | |
geom_smooth(method = "lm") + | |
expand_limits(y = c(0, 60)) + | |
coord_polar(start = 0, theta = "y") | |
with_ggtrace( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inner_fn <- function() { | |
cat("-- Entering Inner Function --\n") | |
# This step of the body is targeted by `at = 3L` in `trace()` | |
cat("-- Exiting Inner Function --\n") | |
return("inner_fn") | |
} | |
outer_fn <- function() { | |
cat("---- Entering Outer Function ----\n") | |
x <- inner_fn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtrace) | |
library(ggplot2) | |
library(ggh4x) | |
# Example from - https://teunbrand.github.io/ggh4x/articles/Facets.html ---- | |
## Base plot ==== | |
p <- ggplot(mpg, aes(displ, hwy, colour = as.factor(cyl))) + geom_point() + | |
labs(x = "Engine displacement", y = "Highway miles per gallon") + | |
guides(colour = "none") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtrace) | |
library(ggplot2) | |
library(grid) | |
p <- ggplot(na.omit(palmerpenguins::penguins)) + | |
aes(bill_length_mm, bill_depth_mm) + | |
geom_point(aes(color = sex)) + | |
facet_wrap(~ species, scales = "free") | |
angles <- rep(seq(0, 360, by = 15), times = 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtrace) # v0.4.8 | |
library(ggplot2) | |
set.seed(20220207) | |
# Step 1: Make plot | |
barplot_plot <- ggplot(data = palmerpenguins::penguins) + | |
geom_bar( | |
aes(x = species, fill = species, group = interaction(species, island)), | |
color = "white", size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggtrace) | |
library(grid) | |
p <- ggplot(mtcars, aes(mpg, hp, color = factor(cyl))) + | |
geom_point() | |
new <- with_ggtrace( | |
x = p, | |
method = ggplot2:::ggplot_gtable.ggplot_built, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggtrace) | |
library(ggplot2) | |
boxplot_plot <- ggplot(na.omit(palmerpenguins::penguins)) + | |
aes(x = island, group = species) + | |
stat_count( | |
aes(fill = species), | |
position = position_fill(), | |
show.legend = FALSE | |
) + |