Open wordsmith189 opened 5 years ago
Sorry for the delayed response. I got a chance to run your example, and I'm not sure what I am supposed to see.
Could I please ask if you can help me to understand your issue?
library(tidyverse)
library(scales)
#>
#> Attaching package: 'scales'
#> The following object is masked from 'package:purrr':
#>
#> discard
#> The following object is masked from 'package:readr':
#>
#> col_factor
library(ggthemes)
library(ggrepel)
set.seed(42)
df <- data.frame(
vowel = c(
"CHOICE", "DRESS", "FACE", "FLEECE", "FOOT",
"GOAT", "GOOSE", "KIT", "LOT/PALM/START", "MOUTH",
"NURSE", "PRICE", "STRUT", "THOUGHT", "TRAP/BATH"
),
vowelclass = c(
"long", "short", "long", "long", "short", "long", "long", "short",
"long", "long", "long", "long", "short", "long", "short"
),
F1nuc = c(
432.2298, 470.0430, 411.0955, 348.8965, 396.5128, 445.1375, 349.9190,
401.3571, 521.6027, 482.3714, 398.9484, 500.4809, 472.9490, 477.1944,
533.7897
),
F2nuc = c(
1072.064, 1499.041, 1772.628, 1825.357, 1418.273, 1275.455, 1443.043,
1611.058, 1249.752, 1502.553, 1365.589, 1419.620, 1347.935, 1171.713,
1535.666
)
)
# make the plot
ggplot(data = df, aes(x = F2nuc, y = F1nuc)) +
scale_x_reverse(name = "F2 (Hz)") +
scale_y_reverse(name = "F1 (Hz)") +
geom_label_repel(
data = subset(df, F2nuc > 1600),
aes(label = vowel),
nudge_x = 2200 - subset(df, F2nuc > 1600)$F2nuc,
segment.size = 0.2,
direction = "y",
hjust = 1
) +
geom_label_repel(
data = subset(df, F2nuc < 1600),
aes(label = vowel),
nudge_x = 1050 - subset(df, F2nuc < 1600)$F2nuc,
segment.size = 0.2,
direction = "y",
hjust = 0
) +
geom_point(size = 4, color = "black") +
facet_wrap(~vowelclass) +
scale_fill_grey() +
theme_bw() +
labs(
title = "Long and short vowel systems",
subtitle = "Control group",
caption = (expression(paste(italic("N")[English], " = 20,992")))
)
Created on 2019-11-03 by the reprex package (v0.3.0)
Summary
In my chart I can either use subsetting in the nudge_x argument to
geom_label_repel()
, like thisor I can use
facet_wrap()
to break out my plot into two panels by one of the group factors. But I can't do both: when I keep both thenudge_x
and thefacet_wrap
in the call toggplot
, things crash.Minimal code example
Here is the code that does not work because it contains both the
facet_wrap
and thenudge
elements. If I leave either of them out, I at least get a plot - but it'd be great to use both of them.Created on 2019-06-08 by the reprex package (v0.3.0)
Version information
Here is the output from
sessionInfo()
in my R session: