Introduction

Plots of all sorts follow. Feel free to cannibalize anything you like.

Axis Scaling

Adjustments (limits, breaks, etc.). ggplot2 can be a bit challenging regarding axes. Let’s first generate a dataframe populated with randomly sampled data from 1-100 without replacement. Then plot it.

baseplot <- ggplot(dat, aes(X1, X2)) + geom_point(shape = 21, fill = "blue", size = 2.3,
    alpha = 0.6) + jamie.theme + ylab(NULL) + xlab(NULL)

breaks

Yuck. We need finer-grained notation on both axes. Add breaks every 10.

newplot <- baseplot + scale_x_continuous(breaks = seq(0, 100, 10), limits = c(0,
    100)) + scale_y_continuous(breaks = seq(0, 100, by = 10))

axis limits

‘xlim’ & ‘ylim’ can cut off data. Tread lightly. Here is what xlim=50 looks like.

smaller <- baseplot + xlim(c(0, 50))

coord_cartesian

Coord_cartesian zooms in on a specific range without cutting/eliminating data

focused <- baseplot + coord_cartesian(xlim = c(0, 25), ylim = c(0, 50))


# Bar plots ## boxplot It’s easy to forget that the crossbar reflects the median not the mean. The components of the box are Q1, Q2 (median), Q3. The whiskers represent the min, max. Let’s construct a boxplot from scratch from a bogus sample composed of 5 observations (e.g., kids shoe sizes): 3,4,5,6,7. Stat 101: The box is defined by the interquartile range (Q2-Q3). The crossbar is the median (here it’s 5). The whiskers represent max and min (that are not outliers). The trick to getting the whiskers here is to generate the error bar and then plop the boxplot over it. The width on the box and the whispers should match.

ggplot(seq7, aes(x = "", y = shoe.size)) + stat_boxplot(geom = "errorbar", width = 0.3) +
    xlab(NULL) + scale_y_continuous(breaks = seq(0, 10, 2), limits = c(0, 10)) +
    geom_boxplot(fill = "blue", width = 0.3) + jamie.theme

violin plot

Here’s a violin plot reflecting salience of 40k English words by vision, olfaction, taste, touch, audition from the Lancaster Sensorimotor Norms. I added a crossbar representing the mean of each distribution.

ggplot(sense.long, aes(x = Sensory, y = Likert, fill = Sensory)) + xlab("Sensory") +
    scale_y_continuous(breaks = seq(0, 5, 1), limits = c(0, 5)) + geom_violin() +
    jamie.theme + ylab("Mean Likert Scale Value") + xlab("Sensory Modality") + stat_summary(fun.y = mean,
    fun.ymin = mean, fun.ymax = mean, geom = "crossbar", color = "black", size = 0.4,
    width = 0.3)

## raincloud plot Here’s a lovely combination of a raincloud plot and a boxplot

ggplot(datmlm, aes(cond, arousal)) + ggdist::stat_halfeye(adjust = 0.5, width = 0.3,
    .width = c(0.5, 1)) + geom_boxplot(width = 0.2, outlier.shape = NA) + scale_fill_manual(values = newvec) +
    jamie.theme


Here’s a dolled up version of the plot from Illustrator
## bar + error Barplots aren’t great in terms of representing variance within a particular distribution. There are better alternatives like dotplots or violin plots. Nevertheless, it is sometimes helpful to include a barplot. Here’s one plotting pupil dilation differences as a function of reading curse words relative to neutral words. This takes a bit of fenagling using the melt function. Then create the barplot you need to make sure you are plotting means (if that’s what you want to do) rather than “identity”. It is also crucial to dodge the bars unless you want a stacked bar chart. Finally, you need stat_summary if you want to calculate and add error bars on the fly. This can be tricky to in terms of dodging and specifying the width of the error bars. I like the little slashes on the legend. You get those by passing “show_guide=T” to the geom_bar code.

colvec <- c("gray", "green")
ggplot(dat2, aes(x = StimCond, y = Dilation, fill = WordCond)) + geom_bar(position = "dodge",
    stat = "summary", fun.y = "mean") + scale_fill_manual(values = colvec) + stat_summary(fun.data = mean_se,
    geom = "errorbar", width = 0.2, position = position_dodge(0.9)) + jamie.theme


## color bars by condition Plotting arousal ratings of every word in Goodfellas marking all the curse words on green.

trysmooth <- onlyvals %>%
    mutate(smootharouse = zoo::rollmean(Arousal, k = 5, fill = NA))  #smooth using rolling mean, smooth the arousal time series
colvec <- c("gray", "green")
goodplot <- ggplot(trysmooth, aes(x = Order, y = smootharouse, fill = Condition)) +
    geom_col(position = "dodge") + scale_fill_manual(values = colvec) + jamie.theme
# ggsave('luciagoodfellasplot.pdf')

Correlation Plots

correlogram

Dr. Joshua Troche crowdsourced ratings from 300+ people on 16 semantic dimensions for 750 English words. The correlation matrices and plots to follow reflect the strength of the relationship(s) between factors like sound salience, visual form, loudness. For example, sound and visual form tend to be highly correlated when considering words like ‘dog’. Josh published this work in Frontiers in Human Neuroscience. Coerce the first column to rownames or else you will get a big fat error when R tries to correlate a string with an integer.

MDS_Corr <- read.csv(here("data", "JoshCorr.csv"), row.names = 1)
joshcor <- cor(MDS_Corr, use = "complete.obs")  #compute correlation matrix using the full dataset
corrplot(joshcor, method = "number", diag = F, type = "upper", bg = "palegreen4",
    cl.pos = "n", number.cex = 0.9, col = "black", outline = T, number.digits = 2,
    addgrid.co = "black")

corrplot1

Color scaled using the viridis palette

corrplot(joshcor, method = "shade", col = viridis(12), shade.col = NA, tl.col = "black",
    tl.srt = 45)

corrplot2

Circles are scaled to indicate the strength of the correlation. Colors indicate the direction of the correlation (blue is negative, red is positive). Since this is a symmetrical matrix, I only included the upper diagonal.

josh <- read.csv(here("data", "Exp1_Corrplot.csv"))
corrmat <- cor(josh, use = "complete.obs")  #create a correlation matrix
colnew <- colorRampPalette(c("blue", "white", "red"))(10)  #color palette from blue to red in increments of 10
corrplot(corrmat, method = "circle", type = "upper", tl.srt = 45, tl.cex = 1, col = viridis(12),
    tl.col = "black", diag = F, order = "hclust")

Pairs panels

The first column in the original data contain words. We need to convert these to rownames when we work with correlation matrices and corrplots. This yields a scatterplot matrix.

all <- read.csv(here("data", "db_glascow.csv"), row.names = 1) %>%
    clean_names()  #need this row.names command
smaller <- all %>%
    select(3, 6:8)  #select valence, imageability, age of acquisition, familiarity
# smaller, the select function is also used by another package, do you need to
# specify dplyr
pairs.panels(smaller[, ], method = "pearson", hist.col = "#00AFBB", density = TRUE)

Dendrograms

rectangle

Nobody loves dendrograms more than my recently graduated MA thesis student, Helen Felker, and here’s one of her favorites. This ‘base’ unadorned cluster dendrogram represents semantic relations between words (N=75) rated in Spanish by a Spanish-English bilingual speaker on color, sound, emotion, size, time salience. Here’s the setup.First convert the original data to a distance matrix (Euclidean), then hclust it using Ward’s Method. Then ‘as.dendrogram’ it. Then plot it. Here I struggled a bit with getting the branches of the dendrogram relatively homogeneous in length. The par(mar) function messes with plotting output using four parameters: bottom, left, top, and right. The default is c(5.1, 4.1, 4.1, 2.1).

sp_means <- sp %>%
    group_by(Stim) %>%
    summarise_all(funs(mean(., na.rm = TRUE))) %>%
    as.data.frame()
sp2 <- sp_means[, -1]  #create a new dataframe minus the first column (eliminate what will be rownames)
rownames(sp2) <- sp_means[, 1]  #coerce the first column (Word) into rownames of the dataframe
sp.dist <- dist(sp2)  #to distance matrix, runs hierarchical cluster analysis using complete linkage
sp.clust <- hclust(sp.dist, method = "ward.D")
sp.dend <- as.dendrogram(sp.clust)  #plt.dend <- ggdendrogram(sp.dend, rotate=TRUE)
plt.v1 <- sp.dend %>%
    set("labels_cex", 0.8) %>%
    set("branches_lwd", 1.5) %>%
    set("leaves_cex", 1.5) %>%
    set("labels_col", "blue") %>%
    raise.dendrogram(2)
plot(plt.v1, horiz = T)

triangle

Same dendrogram plotted as a triangle. There’s lots of extra ‘junk’ space at the top. If we focus on the lower leaves, we might be able to discern a bit more structure.

plt.tri <- sp.dend %>%
    set("labels_cex", 0.8) %>%
    set("branches_lwd", 1.5) %>%
    set("leaves_cex", 1.5) %>%
    set("labels_col", "blue") %>%
    raise.dendrogram(2)
plot(plt.tri, horiz = F, type = "triangle")

Zoom in on the previous dendrogram, Cut at 20. Show small leaf & branch nodes.

plt.tri2 <- sp.dend %>%
    set("labels_cex", 0.8) %>%
    set("branches_lwd", 1.25) %>%
    set("leaves_cex", 1.25) %>%
    set("labels_col", "blue") %>%
    set("nodes_pch", 19) %>%
    set("nodes_cex", 0.5)
# plot(plt.tri2, horiz=F, type='triangle')
plot(cut(plt.tri2, 20)$lower[[2]], horiz = F, type = "triangle")

# Heatmaps ## basic Oh the beauty of a nice heatmap. Here’s one using our semantic data. These data represent average Likert-scale ratings on multiple semantic dimensions (color, sound, etc.) for three English words (kite, alligator, reputation). Prep the dataframe by changing it to a matrix, coercing column one to rownames

dat.1 <- dat.d[, -1]  #create a new dataframe minus the first column (eliminate what will be rownames)
rownames(dat.1) <- dat.d[, 1]
mat.1 <- as.matrix(dat.1)
jamie.colors <- colorRampPalette(c("yellow", "red"))(n = 299)
heatmap.2(mat.1, key.title = NA, dendrogram = "none", trace = "none", col = jamie.colors,
    density.info = "none", margins = c(8, 8), cexRow = 1.5)

contour

Sort of like an interpolated heat map

all <- read.csv(here("data", "db_glascow.csv"), row.names = 1) %>%
    clean_names()
all$gls_img <- as.integer(all$gls_img)
all$gls_arousal <- as.integer(all$gls_arousal)
all$gls_aoa <- as.integer(all$gls_aoa)
ggplot(all, aes(gls_img, gls_arousal, z = gls_aoa)) + geom_contour_filled(binwidth = 0.2) +
    xlim(2, 6) + labs(fill = "AoA") + jamie.theme

Histograms

gaussian overlay

Here’s something you don’t see every day. This histogram reflects counts from Likert-Scale ratings of the quality of pairing common English nouns (e.g., rocket) with taboo words (e.g., shit) to form new taboo compounds (e.g., shitrocket). In this particular histogram, I changed the binwidth to .10 and the y-axis to raw counts. Histogram 2 plots an overlay of a normal curve from a set of psycholinguistic norms.

ggplot(profexp2, aes(x = Qualtrics)) + geom_histogram(colour = "black", fill = "goldenrod2",
    binwidth = 0.1) + xlab("Average Likert Scale Rating") + ylab("Word Count Per Bin") +
    jamie.theme + ggtitle("profane noun compounds")

ggplot(Lancaster, aes(x = Olfactory)) + geom_histogram(aes(y = ..density..), colour = "black",
    fill = "green", binwidth = 0.1) + xlab("Likert Rating") + ylab("Density") + jamie.theme +
    ggtitle("dnorm gaussian overlay") + stat_function(fun = dnorm, args = list(mean = mean(Lancaster$Olfactory),
    sd = sd(Lancaster$Olfactory)), color = "black", size = 1)

density

A density plot is like a smoothed histogram. They’re quite pretty. Let’s say you want to examine two distributions, each composed of 1000 observations. It’s Philly kids vs NYC kids on some crazy standardized test. Let’s say the Philly kids score a mean of 80 (sd=2), whereas NYC kids score a mean of 90 (sd=5). The trick was adjusting the alpha on this.

col.vec <- c("goldenrod2", "blue")
ggplot(phlnyc, aes(x = test.score, fill = city)) + geom_density(alpha = 0.5, colour = "white") +
    scale_fill_manual(values = col.vec) + xlab("Test.Score") + ylab("Count") + jamie.theme +
    ggtitle("Pretty")

Line graphs

generic

Just means across time. I eliminated the x-axis line and redrew it as dashed.

ggplot(lvppa, aes(x = lvppa$Month, y = lvppa$Accuracy, colour = lvppa$Item)) + geom_line(size = 1) +
    theme_bw() + theme(axis.line = element_line(colour = "black"), panel.grid.minor = element_blank(),
    panel.border = element_blank(), panel.background = element_blank()) + coord_cartesian(ylim = c(0,
    1.1)) + geom_hline(aes(yintercept = 0), linetype = "dashed") + theme(axis.line.x = element_blank()) +
    theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
    ylab("% Accuracy") + xlab("Time (months)") + geom_point(shape = 17, size = 3) +
    labs(colour = "")

trendline

These curves reflect three response functions of baseline corrected change in pupil size (in mm) elicited during a word monitoring task when people stare at either an unchanging gray screen in darkness, mid-level luminance, or obnoxiously bright light. The data are in long form, factors are reordered (dark, mid, bright).

summary.words <- read.csv(here("data", "Exp2_RSetupPostPipeline_1.0.csv"))
summary.words$lightCond <- factor(summary.words$lightCond, levels = c("dark", "mid",
    "bright"))
newvec <- c("black", "red", "yellow")
ggplot(summary.words, aes(x = bin, y = raw.diff, color = lightCond, fill = lightCond)) +
    geom_smooth(method = loess, alpha = 0.4) + scale_colour_manual(values = newvec) +
    scale_fill_manual(values = newvec) + coord_cartesian(ylim = c(-0.05, 0.2)) +
    coord_cartesian(ylim = c(-0.05, 0.2)) + ylab("Absolute Pupil Dilation (mm)") +
    xlab("Event Duration (bin)") + scale_x_continuous(breaks = pretty(summary.words$bin,
    n = 12)) + jamie.theme

trendline 2

raw <- read.csv(here("data", "Biling_Master_v10.csv"))
raw_cond <- raw %>%
    select(3, 13, 22:27)
cond_piv <- raw_cond %>%
    pivot_longer(3:8, names_to = "Cond", values_to = "value")  #to long form
colslope <- c("green", "gray")  #creates a vector of colors to pass to aes
ggplot(cond_piv, aes(x = CNC.av, y = value, fill = Condition, color = Condition)) +
    geom_smooth(method = "loess") + scale_fill_manual(values = colslope) + scale_color_manual(values = colslope) +
    facet_wrap(~Cond, ncol = 2) + xlab("concreteness") + ylab("likert rating") +
    jamie.theme

line

Line graphs representing group level pupillary responses

ggplot(piv, aes(x = BinSeq, y = diameter, color = Condition)) + stat_summary(fun = mean,
    na.rm = T, geom = "line", size = 0.5) + scale_colour_manual(values = c("green",
    "black", "red")) + stat_summary(fun.data = mean_se, geom = "pointrange", size = 0.2) +
    theme_bw() + ylab("Pupil Diameter Change (mm)") + xlab("Time Bin") + theme(legend.position = c(0.85,
    0.85)) + jamie.theme + ggtitle("Line Graph w Error Bars")

pointrange

These pupil response functions reflect pupil diameter to Yes/No responses when people think of darkness (dark cave) associated with “No” and brightness (sunny day) associated with “Yes”.

mycolors <- c("goldenrod2", "black")
pupit <- ggplot(pupiv, aes(Time, pupil, color = COND)) + stat_summary(fun.data = mean_se,
    geom = "pointrange", lwid = 0.5, size = 0.3) + scale_color_manual(values = mycolors)

spaghetti

Here’s a spaghetti plot illustrating change from baseline to followup in a cohort of 30 adults. This has a horizontal line annotation marking threshold for impairment on the Montreal Cognitive Assessment.

spag <- read.csv(here("data", "Spaghetti.csv"))
ggplot(spag, aes(x = time, y = value, color = Participant)) + geom_point() + geom_line() +
    scale_y_continuous(breaks = seq(10, 30, 2), limits = c(10, 30)) + geom_hline(yintercept = 25,
    color = "black", size = 1, lty = 5, alpha = 0.6) + jamie.theme + facet_wrap(~GroupImpair)

Scatterplots

dotplot

Here’s a nice alternative to boxplots, reflecting individual differences in average uncorrected pupil diameters for a bunch of neurotypical adults measured in very bright, medium, and dark ambient light. Conditions are colored by a custom vector (in code block below as ‘newvec’). Here are the first 5 rows of the molten dataframe.

newvec <- c("black", "red", "yellow")
ggplot(s, aes(light, pupil, shape = light, fill = light)) + geom_point(shape = 21,
    color = "black", size = 2.3, alpha = 0.6, position = position_jitter(w = 0.03,
        h = 0)) + scale_fill_manual(values = newvec) + ylab("Raw Pupil Size (mm)") +
    ylim(c(2, 5)) + stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean,
    geom = "crossbar", color = "black", size = 0.4, width = 0.3) + jamie.theme

fitline

Mostly linear relation with a wee bit of random jitter around each observation, fitting an LM

test$linear <- jitter(test$ground * 5, 30)
ggplot(test, aes(ground, linear)) + geom_point(shape = 2, size = 2, alpha = 0.7) +
    xlab("Base") + ylab("linear") + geom_smooth(method = "lm", color = "seagreen4") +
    jamie.theme + ggtitle("linear relation")

fitline 2

This scatterplot shows the correlation between concreteness and imageability across many nouns from the MRC Psycholinguistic Database. For some reason CNC gets read in as a factor and must be coerced to integer for this to work. The trendline here uses a Loess function.

ggplot(cnc, aes(x = CNC, y = IMG)) + geom_point(shape = 2, size = 1, color = "Blue",
    alpha = 0.7) + stat_smooth(method = glm, color = "red") + xlab("Concreteness") +
    ylab("Imageability") + scale_x_continuous(breaks = seq(0, 600, by = 100)) + scale_y_continuous(breaks = seq(0,
    600, by = 100)) + jamie.theme

Time Series

Here’s a time series representing continuous sampling of pupil diameter.

pupil.ts <- as.ts(pupil)  #recodes first column to time series (3000 observations of pupil diameter fluctuations)
plot.ts(pupil.ts, ylim = c(3, 5), xlim = c(0, 3000), ylab = "pupil dm (mm)", xlab = "samples",
    col = "red")

Smoothing

Apply a simple moving average to the original time series and then replot it. TTR’s simple moving average (SMA) function averages each new datapoint with the N data points before it to create a new smoothed time series. This takes care of “weird” artifacts like your eyetracker behaving crazily. Here’s what smoothing at a backward window of 10 items looks like – less jagged than the original.

ts.smooth <- ts(SMA(pupil$size, n = 10))
plot.ts(ts.smooth, ylim = c(3, 5), xlim = c(0, 3000), ylab = "pupil dm (mm)", xlab = "samples/time",
    col = "blue", lwid = 3)



## Time series with fit line

theme_s <- ts(tbaf %>%
    select(thematic))  #As smoothed time series
tt_them <- 1:length(theme_s)
fit_them <- ts(loess(theme_s ~ tt_them, span = 0.2)$fitted, start = 1, frequency = 1)
plot.ts(theme_s, col = "grey", main = "To Build a Fire: Thematic Semantic Distance w/ Breakpoints",
    bty = "L", xlab = "sentence#", ylab = "cosine distance (normalized)")
lines(fit_them, col = "darkgreen")



Here is the full figure bundled together and prepped in Illustrator


Color bar marks event onsets in time series

This took me forever to figure out. I wanted to generate a color bar illustrating event onsets within an event-related pupillometry study. The key is that you have to tell ggplot a start and end point for the rectangle. there wasn’t an endpoint in my original data since the x-axis was just a sequential sample. So I created one by adding 1 to the original sample.The white “holes” in the color bar represent filler trials

colvec <- c("white", "green", "red")
ggplot(dat, aes(start, size)) + geom_line() + scale_x_continuous(breaks = seq(0,
    308000, by = 25000)) + coord_cartesian(ylim = c(0, 1250)) + geom_rect(aes(fill = cond),
    xmin = dat$start, xmax = dat$end, ymin = 1100, ymax = 1200) + scale_fill_manual(values = colvec) +
    jamie.theme

Facetting

This plot also has some nice jitter, colors, and opacity on the points.These data represent different measures of pupil size. Some steps in structuring the data….

sc$variable <- factor(sc$variable, levels = c("low", "mid", "high"))  #reorder the factors
newvec <- c("black", "red", "yellow")
ggplot(sc, aes(variable, value, shape = variable, fill = variable)) + geom_point(shape = 21,
    color = "black", size = 2.3, alpha = 0.6, position = position_jitter(w = 0.17,
        h = 0)) + scale_fill_manual(values = newvec) + facet_wrap(~condition, scales = "free_y") +
    ylab("Pupil Dilation (mm)")  #NB all the y-axis have different scales and must scale free.

ROC and Mosaic

Mosaic plot

This is like a visual representation of a confusion matrix for a binary classification table.

conting_semdistz1 <- table(together$Switch_SemDistZ1, together$switch_real)
mosaicplot(conting_semdistz1)


ROC plot

Here’s a receiver operator characteristic (ROC) curve showing sensitivity by 1-specificity for a binary classifer. In this case, we evaluated classification accuracy for semantic distance as a marker of verbal fluency cluster membership.

roc1 <- rocit::rocit(together$Switch_SemDistZ1, together$switch_real)
plot(roc1, values = F)



Here are the ROC and Mosaic plots bundled together and prepped in Illustrator

Color and Aesthetics

Creating and applying custom color vectors

# tbd

Themes

My custom theme for ggplot2 is a minimalist home brew of a theme for ggplot2. I’ll add this to most of the plots to follow. It strips panel gridlines and all sorts of other default junk. To apply different themes, we will work from the ggthemes package.

Jamie custom

jamie.theme <- theme_bw() + theme(axis.line = element_line(colour = "black"), panel.grid.minor = element_blank(),
    panel.grid.major = element_blank(), panel.border = element_blank(), panel.background = element_blank(),
    legend.title = element_blank())

minimal

pupit + theme_minimal() + ggtitle("minimal")

classic

pupit + theme_classic() + ggtitle("classic")

void

pupit + theme_void() + ggtitle("void")

Annotation

label points

Sometimes reference lines are very useful for examining thresholds of impairment, shapes of trends, and other important aspects of the data. Let’s create some fake data highlighting where a critical observation (Dr. No) falls within an X-Y scatterplot of height and weight.

ggplot(e, aes(height, weight, color = group)) + geom_point(size = 3, alpha = 0.6) +
    scale_color_manual(values = myvec) + ylab("weight") + ylab("weight") + theme_classic() +
    ggtitle("Isolating Dr. No")
p <- ggplot(e, aes(height, weight, color = group)) + geom_point(size = 3, alpha = 0.6) +
    scale_color_manual(values = myvec) + ylab("weight") + ylab("weight") + theme_classic() +
    ggtitle("Label Dr. No") + geom_label_repel(aes(label = obs))
print(p)  #labels and repels points

Label Dr. No

p <- ggplot(e, aes(height, weight, color = group)) + geom_point(size = 3, alpha = 0.6) +
    scale_color_manual(values = myvec) + ylab("weight") + ylab("weight") + theme_classic() +
    ggtitle("Label Dr. No") + geom_label_repel(aes(label = obs))
print(p)  #labels and repels points

zero in

Figure out Dr. No’s X and Y coordinates. Then zero in on him in two possible ways. The geom_segment method is a bit of a pita, but it allows precise control of endpoints.

p + geom_hline(yintercept = 65, linetype = "dashed", color = "darkred") + geom_vline(xintercept = 13,
    linetype = "dashed", color = "darkred") + ggtitle("Method 1: Hline & Vline") +
    annotate("text", x = 30, y = 69, label = "Here's Dr. No", color = "darkred",
        size = 6)  #annotate using vline and hline

more labels

p + geom_segment(x = 13, y = 0, xend = 13, yend = 65, linetype = "dashed", color = "blue") +
    geom_segment(x = 0, y = 65, xend = 13, yend = 65, linetype = "dashed", color = "blue") +
    ggtitle("Method 2: Geom_Segment")  #each line segment is a separate geom

ggrepel to nudge the labels so that there is less overlap.

ggplot(profane, aes(Social_Accept, Arousal, color = Condition)) + geom_point(size = 3) +
    ylab("Physiological Arousal") + xlab("Social Acceptibility") + scale_color_manual(values = c("black",
    "green")) + geom_text_repel(aes(label = Word), color = "black", size = 3) + theme(legend.position = c(0.85,
    0.85)) + theme(legend.background = element_rect(fill = "white", color = "black")) +
    theme(axis.line = element_line(colour = "black"), panel.border = element_blank(),
        panel.background = element_blank()) + theme(panel.grid.minor = element_line(colour = "gray",
    size = 0.1))

geom_label

Here’s a plot where the points reflect labels. In this case, the data reflect word pairs

ggplot(mydists, aes(x = as.numeric(row.names(mydists)), y = Sd15_CosRev0Score)) +
    geom_line(color = "#02401BD9", size = 1) + theme_classic() + xlab("bigram position in language transcript") +
    scale_x_continuous(limits = c(0, 6), breaks = c(0, 1, 2, 3, 4, 5, 6)) + ylab("cosine distance (normalized 0-2)") +
    geom_label_repel(aes(label = wordpair), linewidth = 3, data = mydists) + ylim(0,
    0.5)
ggsave("pangramplot_semdist15.pdf")

Illustrator dolled up version…. This involved embedding the last plot (using ggsave) and postprocessing in Adobe Illustrator.

Orphaned Snippets