What I would like to do is:
a) have the plot produced by the ggplot
code be the same each time it runs [set.seed kind of notion?] and
b) have text labels jittered only for labels that have the same y-axis value -- leave the other text labels alone. This would seem to be some kind of conditional jittering based on a factor value for the points.
Here is some data:
dput(df)
structure(list(Firm = c("a verylongname", "b verylongname", "c verylongname",
"d verylongname", "e verylongname", "f verylongname", "g verylongname",
"h verylongname", "i verylongname", "j verylongname"), Sum = c(74,
77, 79, 82, 85, 85, 88, 90, 90, 92)), .Names = c("Firm", "Sum"
), row.names = c(NA, 10L), class = "data.frame")
Here is ggplot
code using df:
ggplot(df, aes(x = reorder(Firm, Sum, mean), y = Sum)) +
geom_text(aes(label = Firm), size = 3, show.guides = FALSE, position = position_jitter(height = .9)) +
theme(axis.text.x = element_blank()) +
scale_x_discrete(expand = c(-1.1, 0)) + # to show the lower left name fully
labs(x = "", y = "", title = "")
Notice one version of the plot still overlaps h and i -- each time I run the above code the locations of the text labels change.
BTW, this question conditional jitter shifts the discrete values on the x-axis a bit, but I would like to shift the overlapping points (only) on the y-axis.