df <- data.frame(
x = c(0, 0, 1, 1, 0.5),
x.chr = c("left", "left", "right", "right", "center"),
y = c(0, 1, 0, 1, 0.5),
y.chr = c("bottom", "top", "bottom", "top", "middle"),
text = c("bottom-left", "top-left", "bottom-right", "top-right", "center-middle")
)
ggplot(df) +
geom_text_npc(aes(npcx = x, npcy = y, label = text))
ggplot(df) +
geom_text_npc(aes(npcx = x.chr, npcy = y.chr, label = text))
ggplot(df) +
geom_text_npc(aes(npcx = x.chr, npcy = y.chr, label = text),
angle = 90)
ggplot(data = mtcars, mapping = aes(wt, mpg)) +
geom_point() +
geom_text_npc(data = df, aes(npcx = x, npcy = y, label = text))
ggplot(data = mtcars, mapping = aes(wt, mpg)) +
geom_point() +
geom_text_npc(data = df, aes(npcx = x, npcy = y, label = text)) +
expand_limits(y = 40, x = 6)
ggplot(data = mtcars) +
geom_point(mapping = aes(wt, mpg)) +
geom_label_npc(data = df, aes(npcx = x, npcy = y, label = text))
ggplot(data = mtcars) +
geom_point(mapping = aes(wt, mpg)) +
geom_label_npc(data = df, aes(npcx = x.chr, npcy = y.chr, label = text),
angle = 90) # ignored by ggplot2 < 3.5.0
Run the code above in your browser using DataLab