In issue #1435 on adjusting element_text, we find that "vjust and hjust no longer work. Instead, use the margin() parameter of element_text()". Does this apply also for legend.text?
I have a plot in which I want to adjust the legend.text horizontally.
df <- data.frame(x = c("a", "b"), y = 1)
p <- ggplot(df, aes(x = x, y = y, fill = x)) +
geom_bar(stat = "identity") +
ggtitle("My plot")
p
I followed the suggestion in #1435: "if you're having problems understanding the layout, try debug = TRUE":
p + theme(text = element_text(debug = TRUE))
I am not entirely sure I interpret the "debugging plot" correctly, but I thought it indicated all text elements which could be adjusted. Here, areas corresponding to axis.text, axis.title, and plot.title, are highlighted, but seemingly not those for legend.text (nor for legend.title).
I have tried to "push" and "pull" the legend.text horizontally using
p + theme(legend.text = element_text(margin = margin(l = , r = )))
...with various combinations of l and r, to no avail.
Thus my question: is legend.text (and legend.title) not included among the element_text elements which can be adjusted using margin? Which is the current ''official' way to adjust these elements?
In issue #1435 on adjusting
element_text, we find that "vjustandhjustno longer work. Instead, use themargin()parameter ofelement_text()". Does this apply also forlegend.text?I have a plot in which I want to adjust the
legend.texthorizontally.I followed the suggestion in #1435: "if you're having problems understanding the layout, try
debug = TRUE":I am not entirely sure I interpret the "debugging plot" correctly, but I thought it indicated all text elements which could be adjusted. Here, areas corresponding to
axis.text,axis.title, andplot.title, are highlighted, but seemingly not those forlegend.text(nor forlegend.title).I have tried to "push" and "pull" the
legend.texthorizontally using...with various combinations of
landr, to no avail.Thus my question: is
legend.text(andlegend.title) not included among theelement_textelements which can be adjusted usingmargin? Which is the current ''official' way to adjust these elements?