The attached code file provides an easy basic interface to the Wolfram Alpha API. Inspired by the wolframalpha module available for Python.
source("wa_lib.R")
### slightly adapted from here to save png or pdf and specify resolution etc: https://stackoverflow.com/questions/43051525/how-to-draw-pheatmap-plot-to-screen-and-also-save-to-file | |
# function detects '.png' or '.pdf' in the declared filename and assigns that file type | |
### pheatmap save function | |
save_pheatmap <- function(x, filename, width=12, height=12){ | |
stopifnot(!missing(x)) | |
stopifnot(!missing(filename)) | |
if(grepl(".png",filename)){ | |
png(filename, width=width, height=height, units = "in", res=300) |
### prep data | |
Xdata <- data %>% select(-outcome) %>% as.matrix() | |
Ydata <- as.matrix(data$outcome) | |
### definte stability function | |
LassoSub=function(k=1, Xdata, Ydata){ | |
set.seed(k) | |
s=sample(nrow(data), size=0.8*nrow(data)) | |
Xsub=Xdata[s, ] | |
Ysub=Ydata[s] |
### Install packages | |
list.of.packages <- c("citr", "colourpicker", "rcrossref", "jpeg","RCurl") ### add all the packages that are used in your script here | |
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] ### check if they are installed | |
if(length(new.packages)) install.packages(new.packages) ### install any that need installing | |
### Load packages | |
lapply(list.of.packages, require, character.only = TRUE) |
### define function for conversion to scientific notation of p-values or other numeric values | |
scientific_notation <- function (values, digits = 1) | |
{ | |
if (!is.numeric(values)) { | |
stop("values must be numbers") | |
} | |
if (grepl("^\\d{2}$", digits)) { | |
stop("digits must a one or two digit whole number") | |
} | |
x <- sprintf(paste0("%.", digits, "e"), values) |
### Functions for calculating Elo probabilities and scores ### | |
# Uses the weighted Elo formula created by 538, with a K of 250, a shape of 0.4 and an offset of 5 | |
# https://fivethirtyeight.com/features/how-were-forecasting-the-2016-us-open/ | |
### Define a function that calculates probabilities on the basis of Elo score inputs | |
#p1elo is p1's current Elo score |
# Create table 1 ------------------------------------ | |
library(tableone) | |
myVars <- c("var1","var2") ### create list of variables to include intable | |
# Make sure any categorical variables are saved as factors | |
MyData$var2 <- as.factor(MyData$var2) | |
# package says to pass a list of categorical variables separately but this doesn't seem to work | |
# passing categorical variables in the main variable list works, so long as they are saved as factors |
# load packages | |
library(ggmap) | |
library(ggplot2) | |
library(ggthemes) | |
### set up a google API for google static maps at https://developers.google.com/maps/documentation ### | |
# register key | |
register_google(key = "XXXXXXXXXXXXXXX") |
The attached code file provides an easy basic interface to the Wolfram Alpha API. Inspired by the wolframalpha module available for Python.
source("wa_lib.R")
The Chartmaker directory has a nice matrix showing which tools can be used to produce many kinds of chart, with examples of how.
Two new tools allow you to interactively create bespoke chart layouts without programming