I am trying to move the two legend text labels to the top and bottom of the colored legend, respectively. The hjust and vjust argument successfully moves the first text label, but does not change the second. I've tried using c() or even mutating a "newvjust" variable to use in the argument, but am given an "error in valid.viewport...must all be units of length 1."
Here is some relevant code (renamed generically), and a picture of where I've gotten thus far.
p <- ggplot(data, aes(xvar, yvar)) +
geom_tile(aes(fill = colour)) +
# ggtitle("Heatmap") +
labs(x = "xaxis",
y = "yaxis") + theme_classic() +
theme(axis.text.y = element_text(angle = 17.43, hjust = 1, size = 5),
legend.justification = c(0, 1),
legend.position = "right",
legend.text=element_text(size = 3.7, vjust = 1.5, hjust = -2)) +
scale_x_continuous(breaks = c(106:115)) +
geom_vline(xintercept = c(106.5, 107.5, 108.5, 109.5, 110.5, 111.5, 112.5, 113.5, 114.5, 115.5), alpha = 0.15) +
geom_hline(yintercept = c((1:126) + .5), alpha = .15)
p + scale_fill_manual(values = c("lightblue",
"green"),
labels = c("Legend Label 1",
"Legend Label 2"),
name = NULL)
As you see, only the "Lab1" legend text is moving, though I want Lengend Label 2 to appear at the bottom:
Thanks in advance!!