--- title: Interaction plots with ggplot2 author: Jeff Walker date: '2018-10-15' slug: interaction-plots-with-ggplot2 categories: - ggplot tags: - interaction - categorical X ---
ggpubr is a fantastic resource for teaching applied biostats because it makes ggplot a bit easier for students. I’m not super familiar with all that ggpubr can do, but I’m not sure it includes a good “interaction plot” function. Maybe I’m wrong. But if I’m not, here is a simple function to create a gg_interaction plot.
The gg_interaction function returns a ggplot of the modeled means and standard errors and not the raw means and standard errors computed from each group independently. The modeled means and errors are computed using the emmeans function from the emmeans package. If a random term is passed, gg_interaction uses the function lmer, from the package lme4, to fit a linear mixed model with the random term as a random intercept.
(requires ggplot2, data.table, and emmeans)
gg_interaction <- function(x, y, random=NULL, data){
# x is a vector of the column labels of categorical variables
# y is the response column
# random is a column name of a blocking factor
# data is a data.frame or data.table
dt <- data.table(data)
fixed_part <- paste(y, "~", paste(x[1], x[2], sep="*"))
if(is.null(random)){ # linear model
lm_formula <- formula(fixed_part)
fit <- lm(lm_formula, data=dt)
}else{ ## linear mixed model
random_part <- paste("(1|", random, ")", sep="")
lmm_formula <- formula(paste(fixed_part, random_part, sep=" + "))
fit <- lmer(lmm_formula, data=dt)
}
fit.emm <- data.table(summary(emmeans(fit, specs=x)))
new_names <- c("f1", "f2")
setnames(fit.emm, old=x, new=new_names)
pd <- position_dodge(.3)
gg <- ggplot(data=fit.emm, aes(x=f1, y=emmean, shape=f2, group=f2)) +
#geom_jitter(position=pd, color='gray', size=2) +
geom_point(color='black', size=4, position=pd) +
geom_errorbar(aes(ymin=(emmean-SE), ymax=(emmean+SE)),
color='black', width=.2, position=pd) +
geom_line(position=pd) +
xlab(x[1]) +
ylab(y) +
theme_bw() +
guides(shape=guide_legend(title=x[2])) +
theme(axis.title=element_text(size = rel(1.5)),
axis.text=element_text(size = rel(1.5)),
legend.title=element_text(size = rel(1.3)),
legend.text=element_text(size = rel(1.3))) +
NULL
return(gg)
}
I use data from a study of the synergistic effect of UVB and temperature on infection intensity (citations below) to show how to use the function. The data are from a 2 x 2 factorial experiment and with a single blocking (random) factor “tank”.
Dryad source: Cramp RL, Reid S, Seebacher F, Franklin CE (2014) Data from: Synergistic interaction between UVB radiation and temperature increases susceptibility to parasitic infection in a fish. Dryad Digital Repository. https://doi.org/10.5061/dryad.74b31
Article Source: Cramp RL, Reid S, Seebacher F, Franklin CE (2014) Synergistic interaction between UVB radiation and temperature increases susceptibility to parasitic infection in a fish. Biology Letters 10(9): 20140449. https://doi.org/10.1098/rsbl.2014.0449
library(ggplot2)
library(readxl)
library(data.table)
library(lme4)
library(emmeans)
data_path <- "../data"
folder <- "Data from Synergistic interaction between UVB radiation and temperature increases susceptibility to parasitic infection in a fish"
filename <- "Cramp et al raw data.xlsx"
file_path <- paste(data_path, folder, filename, sep="/")
fish <- data.table(read_excel(file_path, sheet="Infection Intensity"))
setnames(fish, old=colnames(fish), new=c("UV", "Temp", "Tank", "Whitespots"))
fish[, UV:=factor(UV, c("Low", "High"))]
fish[, Temp:=factor(Temp)]
gg <- gg_interaction(x=c("UV", "Temp"), y="Whitespots", random="Tank", data=fish)
gg


My name is KG and I am a Full-Stack Software Artisan (Resume) who works with startups/small businesses to develop rapid software Prototypes/MVPs. Build it fast and cheaply, test it without spending a fortune on development.
Sell Hub is a classifieds ads/listing site similar to OLX or Craig's List. Built using Ionic (front end), Python Django (back end) and PostgresSQL(database). This is a hybrid application that can be viewed on browsers and compiled into an android app. The app was deployed to Heroku (back end), Firebase (front end) and AWS (media files). Click here to download the android app →
Conduit is a social blogging site similar to Medium/Tumblr. Modified from Thinkster's open source app using Ionic (front end), Node/Express (back end) and MongoDB(database). This is a hybrid application that can be viewed on browsers and compiled into an android app. The app was deployed to Heroku (back-end) and Firebase (front end and media files). Click here to download the android app →
Click to see browser demo →Conduit is a social blogging site similar to Medium/Tumblr. Modified from Thinkster's open source app using Angular (front end), Node/Express (back end) and MongoDB(database). The app was deployed to Heroku (back-end) and Firebase (front end and media files)
Click to see demo →Hybrid application that can be viewed on browsers and compiled into an android app. Click here to download the android app →
Click to see demo →Angular Browser app that can also be compiled to android mobile app with Cordova
Click to see demo →An UberEats clone where restaurant users can create restaurants, menu's and meals. The stack used was Python Django front and back end deployed to Heroku and AWS (media files).
Click to see demo →An UberEats clone and mobile app where customers can sign in using Facebook, create, pay for and track orders (Android Java).
Download Android APK file →An UberEats clone and mobile app where drivers can pick orders, deliver to the customer and track their weekly income (Android Java).
Download Android APK file →


"The payroll that I am running next week will have 4 new employees on it! By the middle of next month, I should have another 3 employees! This couldn't have been possible without the new software."
HTML5
CSS3
Bootstrap
JavaScript
jQuery
SQL Server
C #
.NET
Visual Studio
This startup needed to automate its data processes to free up time to focus on growth. The software streamlined their record-keeping and invoice submissions.
Close ProjectThis app was built with accessibility for a legally blind individual in mind. It allows her to call client contacts without dialing and to dictate her notes.
Close ProjectThis project displays the use of JavaScript, jQuery, Bootstrap, HTML, and CSS.
See code at:
https://github.com/mghall25/Pizza-Order-Form
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia neque assumenda ipsam nihil, molestias magnam, recusandae quos quis inventore quisquam velit asperiores, vitae? Reprehenderit soluta, eos quod consequuntur itaque. Nam.
Close ProjectLorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia neque assumenda ipsam nihil, molestias magnam, recusandae quos quis inventore quisquam velit asperiores, vitae? Reprehenderit soluta, eos quod consequuntur itaque. Nam.
Close ProjectLorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia neque assumenda ipsam nihil, molestias magnam, recusandae quos quis inventore quisquam velit asperiores, vitae? Reprehenderit soluta, eos quod consequuntur itaque. Nam.
Close Project


Poisoned farm costs sellers
by The Canadian PressA "vindictive" and "malicious" decision by two British Columbia blueberry farmers to poison their fields rather than hand over the farm in a court-ordered sale has cost the two men almost $3 million.
A decision from B.C. Supreme Court Justice Geoffrey Gomery finds the damage to the farm in Langley by former owners Zora and Harminder Grewal was "pointless" and will be felt for more than a decade.
Gomery says in the decision that although the case against the brothers is circumstantial, there are "no other plausible candidates" who could have sprayed almost 24-hectares of healthy blueberries with chemicals, destroying the crop just as the farm changed hands.
The new owners, Malkiat and Satwant Baring, had purchased the property for $5.5-million in a foreclosure sale in June 2017 and, after an unsuccessful appeal by the Grewals, took over the farm a month later.
The decision says the damage to the crop was readily apparent on the afternoon the Barings took over the farm, despite an inspection just seven days earlier that found the productive bushes were almost ready for harvest.
Gomery has ordered the purchase price of the farm be cut by nearly $2.8 million and he set punitive damages of $150,000 to denounce the Grewals' misconduct "and give them their just desserts."
"The most troubling aspect of the evidence is the question of motive. Why would the defendants do such a thing? This only takes one so far. Why would anyone do such a thing? Yet someone did," Gomery says in his judgment posted online Monday.
A seven-day trial conducted in Vancouver last month heard Harminder Grewal tried to talk the Baring family out of completing the sale in a conversation Gomery concludes was at least a warning, if not a threat.
It says the Grewals deny saturating the fields with two herbicides, one of them known by the trade name Roundup, but they may have taken the step because they were "angry with the Barings and had a misconceived wish to punish them."


These pages use content from Jeffrey Heath's work on the Nunggubuyu language.The online presentation is being prepared by Nick Thieberger, Simon Musgrave and Brett Baker.Created by Simon Musgrave
Copyright 2011/2018


Collins Nji, who goes by the online alias "Collin Grimm," is a sophomore currently pursuing a BSc in Computer Science with a double minor in Data Science and English Language at Mount St. Mary's University in Maryland. Last summer, Collin interned as a Data Research Analyst at the Georgetown University Center for Security and Emerging Technology.
I was born and raised in Cameroon 🇨🇲— a country in Central Africa. I moved to the USA to continue my college education. I have four sisters, and unfortunately no brother. Cameroon is a bilingual country and the two official languages are English and French. I grew up speaking both, but I also learned Arabic and Pidgin English (creole based English spoken in West Africa and Hawaii). Hence, I speak four languages in total, and I am currently learning German!
In my free time, I like to paint and draw. My drawings mostly depict abstract art scenes. I love charcoal and graphite and I primarily use that media for my drawings. People often say charcoal is messy, but I think if carefully used, it produces the most beautiful images.
This project attempts to use Snorkel to create weak labels for large amounts of training data at Georgetown CSET using weak supervision. The data is primarily paper abstracts, whose relevance to various WIPO Application Areas we explore. This was my summer project at my last internship where I used weak supervision to label about 4GB worth of paper abstracts by writing weak supervision models based on Snorkel
This project uses Google's NLP APIs to create a mind map of someone's thought process, and builds a dynamic mind map that shows both sentiment of thoughts and relationship to other parts of text as the user writes in an editor. This project was inspired by Alfred Prufrock's works in literature. This project uses Node.js for the backend, D3.js for the mind map visualization and JS for the front end.


Encryption Asymmetric Class
Asymmetric Encryption
Item Index
Methods
asym.decrypt
-
decryptKey
-
UNKNOWN
-
onError
-
onSuccess
Decrypt. For large payloads, keys are RSA decrypted and content is AES decrypted. Otherwise, content is RSA decrypted.
asym.encrypt
-
encryptKey
-
data
-
onError
-
onSuccess
Encrypt. For large payloads, the content is AES encrypted and keys are RSA encrypted. Otherwise, the content is RSA encrypted. "Large" trashhold is defined in config.
asym.encryptAndSign
-
decryptKey
-
decryptKey
-
dict
-
onError
-
onSuccess
Encrypt and Sign. For large payloads, the content is AES encrypted and keys are RSA encrypted. Otherwise, the content is RSA encrypted. "Large" trashhold is defined in config. The order of operations is: AES (encrypt if required), encrypt content/keys, sign content/keys, sign encrypted content/keys.
Parameters:
-
decryptKey
CryptoKey- RSA encryption private key
-
decryptKey
CryptoKey- RSA signature public key
-
dict
Object- decoded encrypted object {rsaEncrypted:, signatureOfEncrypted:, signatureOfData:, aesEncrypted?:, hmac?: }
-
onError
Function- called with error details if decrypt fails
-
onSuccess
Function- called with decrypted ArrayBuffer
asym.generateEncryptKey
-
onError
-
onSuccess
Generate RSA encryption keys. Private CryptoKey is not exportable, and can be stored safely.
asym.generateKeys
-
onError
-
onSuccess
Generate RSA encryption and signature keys
asym.generateSignKey
-
onError
-
onSuccess
Generate RSA signature keys. Private CryptoKey is not exportable, and can be stored safely.
asym.importEncryptKey
-
publicJwk
-
privateJwk
-
onError
-
onSuccess
Import RSA encryption keys.
asym.importEncryptPrivateKey
-
publicJwk
-
privateJwk
-
onError
-
onSuccess
Import RSA private encryption keys.
asym.importEncryptPublicKey
-
publicJwk
-
onError
-
onSuccess
Import RSA public encryption keys.
asym.verifyAndDecrypt
-
decryptKey
-
decryptKey
-
dict
-
onError
-
onSuccess
Verify and Decrypt. For large payloads, AES keys are RSA decrypted and content is AES decrypted. Otherwise, content is RSA decrypted. The order of operations is: verify encrypted content/keys, decrypt, verify decrypted content/keys, AES decrypt (if required).
Parameters:
-
decryptKey
CryptoKey- RSA encryption private key
-
decryptKey
CryptoKey- RSA signature public key
-
dict
Object- decoded encrypted object {rsaEncrypted:, signatureOfEncrypted:, signatureOfData:, aesEncrypted?:, hmac?: }
-
onError
Function- called with error details if decrypt fails
-
onSuccess
Function- called with decrypted ArrayBuffer