Background:
I have a kind of Gantt chart, composed of horizontal segments with different events marked by symbols of different shapes. I want the symbols to have exactly the same height as the segment (potential topic for next question!), and symbols should be center aligned within each segment.
Issue:
The problem is that different shapes seem to have different alignment. In my small example, shape
0, 3, 4, 5 are center aligned (four first symbols from left). In contrast, the circle and the two triangles are offset.
d1 <- data.frame(x = -1, xend = 7, y = 1, yend = 1)
d2 <- data.frame(x = 0:6, y = 1)
library(ggplot2)
ggplot(data = d1, aes(x = x, y = y)) +
geom_segment(aes(xend = xend, yend = yend), size = 8, color = "grey80") +
geom_segment(aes(xend = xend, yend = yend), color = "red") +
geom_point(data = d2, shape = c(0, 3, 4, 5, 1, 2, 6), size = 8) +
theme_void()
I have also desperately tried a geom_text
equivalent with unicode symbols. However, the alignment is now even harder to fathom.
geom_text(data = d2,
label = c("\u25A1", "\uFF0B","\u2715","\u25C7", "\u25CB", "\u25B3", "\u25BD"),
size = 8, vjust = "center")
No obvious hints in ?geom_point
, ?aes_linetype_size_shape
or ?pch
. I have googled "r plot align center justify symbol shape pch" - have I missed any keywords?
Question: How can I align different shapes without hardcoding?