my.cars <- mtcars[c(TRUE, FALSE, FALSE, FALSE), ]
my.cars$name <- rownames(my.cars)
# no nudging
ggplot(my.cars, aes(wt, mpg, label = name)) +
geom_text_s() +
expand_limits(x = c(2, 6))
# base plot
p <- ggplot(my.cars, aes(wt, mpg, label = name)) +
geom_point()
# Using nudging
p +
geom_text_s(nudge_x = 0.12) +
expand_limits(x = 6.2)
p +
geom_text_s(nudge_x = -0.12) +
expand_limits(x = 1.5)
p +
geom_text_s(nudge_x = 0.12,
arrow = arrow(length = grid::unit(1.5, "mm")),
point.padding = 0.4) +
expand_limits(x = 6.2)
p +
geom_text_s(nudge_y = 0.1, nudge_x = 0.07) +
expand_limits(x = 6.2)
p +
geom_text_s(nudge_y = 1, angle = 90) +
expand_limits(y = 30)
p +
geom_text_s(angle = 90, nudge_y = 1,
arrow = arrow(length = grid::unit(1.5, "mm")),
colour.target = "segment", colour = "red") +
expand_limits(y = 30)
p +
geom_text_s(aes(colour = factor(cyl)),
angle = 90, nudge_y = 1,
arrow = arrow(length = grid::unit(1.5, "mm")),
alpha.target = "segment", alpha = 0.3) +
expand_limits(y = 30)
p +
geom_label_s(nudge_x = 0.12) +
expand_limits(x = 6.2)
p +
geom_label_s(nudge_x = 0.12, linetype = "dotted", linewidth = 0.3) +
expand_limits(x = 6.2)
p +
geom_label_s(aes(colour = factor(cyl)),
nudge_x = 0.12,
colour.target = "box",
linewidth = 0.5,
label.r = unit(0, "lines")) +
expand_limits(x = 6.2)
p +
geom_label_s(nudge_x = 0.12, linewidth = 0) +
expand_limits(x = 6.2)
# No segments
p +
geom_label_s(nudge_x = 0.05, segment.linewidth = 0) +
expand_limits(x = 6.2)
# Nudging away from arbitrary point
p +
geom_label_s(hjust = "outward_1", nudge_x = 0.12) +
expand_limits(x = 6.2)
p +
geom_label_s(hjust = "inward_3", nudge_y = 0.4)
p +
geom_label_s(nudge_y = 1, angle = 90) +
expand_limits(y = 30)
# Add aesthetic mappings and adjust arrows
p +
geom_text_s(aes(colour = factor(cyl)),
angle = 90,
nudge_y = 1,
arrow = arrow(angle = 20,
length = grid::unit(1.5, "mm"),
ends = "first",
type = "closed")) +
scale_colour_discrete(l = 40) + # luminance, make colours darker
expand_limits(y = 27)
p +
geom_text_s(aes(colour = factor(cyl)),
angle = 90,
nudge_y = 1,
arrow = arrow(angle = 20,
length = grid::unit(1.5, "mm"),
ends = "first",
type = "closed")) +
scale_colour_discrete(l = 40) + # luminance, make colours darker
expand_limits(y = 27)
p +
geom_label_s(aes(colour = factor(cyl)),
colour.target = c("box", "text"),
nudge_x = 0.3,
arrow = arrow(angle = 20,
length = grid::unit(1/3, "lines"))) +
scale_colour_discrete(l = 40) + # luminance, make colours darker
expand_limits(x = 7)
p +
geom_label_s(aes(colour = factor(cyl)),
nudge_x = 0.3,
colour.target = c("box", "segment"),
linewidth = 0.5,
arrow = arrow(angle = 20,
length = grid::unit(1/3, "lines"))) +
scale_colour_discrete(l = 40) + # luminance, make colours darker
expand_limits(x = 7)
p +
geom_label_s(aes(colour = factor(cyl), fill = factor(cyl)),
nudge_x = 0.3,
alpha.target = "box",
alpha = 0.1,
linewidth = 0.5,
arrow = arrow(angle = 20,
length = grid::unit(1/3, "lines"))) +
scale_colour_discrete(l = 40) + # luminance, make colours darker
expand_limits(x = 7)#' # Scale height of text, rather than sqrt(height)
p +
geom_text_s(aes(size = wt), nudge_x = -0.1) +
scale_radius(range = c(3,6)) + # override scale_area()
expand_limits(x = c(1.8, 5.5))
Run the code above in your browser using DataLab