I am having difficulty properly aligning a multi-line legend title that contains math expressions:
# Simulate example data and create plot
df <- data.frame(x = 1:3, y = 1:3, z = 1:3)
gg <- ggplot(df, aes(x, y, colour = z)) geom_point()
# Legend title that is causing problems:
expectation <- bquote(paste("E(\U03BC | ", bold(Z), ", ", bold("\U03B8"), ")"))
legend_title <- bquote(paste("Prediction\n", .(expectation), sep = ""))
gg <- gg labs(colour = legend_title)
gg
CodePudding user response:
I can't comment, but the issue is that expressions default to right justification. See this post for a solution: ggplot right align axis text when using expression