This file contains 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
# Plot length-tension curve of a sarcomere | |
length = c(1.2, 1.7, 2, 2.2, 3.65) # µm | |
force = c(0, 85, 100, 100, 0) # % of maximum force | |
xLabel = "Sarcomere Length (µm)" | |
yLabel = expression("Force (% "*P[0]*")") | |
svg("sarcomere_length_tension_curve.svg", width = 10, height = 5.5) | |
par(mar = c(4, 4, 0, 0.5) + 0.25) # decrease bottom, top and right margin | |
plot(length, force, xlab = xLabel, ylab = yLabel, type = "l", col = "steelblue", | |
bty = "n", xlim = c(0, 4), ylim = c(0, 105), lwd = 2, yaxs = "i", xaxs = "i") |
This file contains 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
suppressMessages(library(dplyr)) | |
data("mtcars") | |
mtcars %>% group_by(cyl) %>% summarise(n = n()) | |
#> # A tibble: 3 x 2 | |
#> cyl n | |
#> <dbl> <int> | |
#> 1 4 11 | |
#> 2 6 7 | |
#> 3 8 14 |
This file contains 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) | |
data(mtcars) | |
filter_a <- TRUE; filter_b <- TRUE; filter_c <- TRUE | |
### Variant 1 ### | |
d <- mtcars | |
if (filter_a) d <- filter(d, am == 0) | |
if (filter_b) d <- filter(d, hp > 10) | |
if (filter_c) d <- filter(d, cyl == 4) |
This file contains 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(ggcharts) | |
library(dplyr) | |
dreaded_lang <- tibble::tribble( | |
~language, ~pct, | |
"VBA", 75.2, | |
"Objective-C", 68.7, | |
"Assembly", 64.4, | |
"C", 57.5, | |
"PHP", 54.2, |
This file contains 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(dplyr) | |
electrial_consumption <- tibble::tribble( | |
~country, ~pct, | |
"Italy", -27, | |
"Spain", -21, | |
"Belgium", -17, | |
"Austria", -16, | |
"France", -16, |
This file contains 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) | |
Sys.setlocale("LC_TIME", "English") | |
stars <- ghstars::get_pkg_star_history("ggcharts") | |
stars <- stars[stars$date <= as.Date("2020-05-19"), ] | |
ggplot(stars, aes(date, cumulative_stars)) + | |
geom_step(color = "darkorange", size = 1.5) + | |
annotate( | |
geom = "label", | |
label = " 100th Star by @JagersbergKnut", |
This file contains 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
`:=` <- function(lhs, rhs) { | |
var <- deparse(substitute(lhs)) | |
if (exists(var, parent.frame(), inherits = FALSE)) { | |
stop("Variable `", var, "` is already defined.", call. = FALSE) | |
} else { | |
assign(var, rhs, parent.frame()) | |
} | |
} | |
# An alternative version making use of `lockBinding`. This prevents users from overwriting |
This file contains 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
do_if <- function(data, predicate, expr) { | |
if (predicate) { | |
eval.parent(insert_data( | |
substitute(expr), | |
substitute(data) | |
)) | |
} else { | |
data | |
} | |
} |
This file contains 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(dplyr) | |
data(biomedicalrevenue, package = "ggcharts") | |
plot <- biomedicalrevenue %>% | |
filter(company %in% c("Roche", "Novartis")) %>% | |
ggplot(aes(year, revenue, color = company)) + | |
geom_line(size = 1.2) + | |
ggtitle( | |
paste0( |
This file contains 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
<span style = 'color:color name or hex code'>Text you want to color</span> |
OlderNewer