Skip to content

Instantly share code, notes, and snippets.

View tanerumit's full-sized avatar
💭
I may be slow to respond.

Umit Taner, Ph.D. tanerumit

💭
I may be slow to respond.
View GitHub Profile
@tanerumit
tanerumit / Custom font in ggplot2.R
Last active January 16, 2021 13:45 — forked from dsparks/Custom font in ggplot2.R
#R #ggplot2 use any font on the system
require(extrafont)
require(ggplot2)
font_import(pattern = "GIL", prompt = FALSE) # Import Gill family
loadfonts(device="win") # Load them all
fonts() # See what fonts are available
zp1 <- ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, label = Species))
zp1 <- zp1 + geom_text(family = "Gill Sans MT")
zp1 <- zp1 + theme(text=element_text(family="Gill Sans Ultra Bold"))
@tanerumit
tanerumit / sourceDir.R
Last active January 16, 2021 13:43
#R #function to source all scripts in a directory
### Sourcing
sourceDir <- function(path, trace = TRUE, ...) {
for (nm in list.files(path, pattern = "\\.[RrSsQq]$")) {
if(trace) cat(nm,":")
source(file.path(path, nm), ...)
if(trace) cat("\n")
}
}
@tanerumit
tanerumit / lmp.R
Last active January 16, 2021 13:44
#R #function to extract p-value from a linear model
lmp <- function (modelobject) {
if (class(modelobject) != "lm") stop("Not an object of class 'lm' ")
f <- summary(modelobject)$fstatistic
p <- pf(f[1],f[2],f[3],lower.tail=F)
attributes(p) <- NULL
return(p)
}
@tanerumit
tanerumit / gganimate_example.R
Last active January 16, 2021 13:44
#ggplot #R #example for animated gifs
library(tidyverse)
library(gganimate)
## standard ggplot2
myPlot <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
# Here comes the gganimate specific bits
@tanerumit
tanerumit / ggplot2_theme_essentials.R
Created February 11, 2021 11:21
Essential #ggplot2 theme settings
https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
theme(
# Legend title and text labels
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Title font color size and face
legend.title = element_text(color, size, face),
# Title alignment. Number from 0 (left) to 1 (right)
legend.title.align = NULL,
# Text label font color size and face