I have a plot that looks like this:
I used these data and code to produce it:
structure(list(zone = c("Zone 1", "Zone 2", "Zone 3", "Zone 4",
"Zone 5", "Total", "Zone 1", "Zone 2", "Zone 3", "Zone 4", "Zone 5",
"Total"), effort = c(3226, 4705, 2443, 131, 276, 10781, 1757,
7293, 1631, 34.4, 442, 11157), creelyear = c("2013-2014", "2013-2014",
"2013-2014", "2013-2014", "2013-2014", "2013-2014", "2022-2023",
"2022-2023", "2022-2023", "2022-2023", "2022-2023", "2022-2023"
)), class = "data.frame", row.names = c(NA, -12L))
df %>%
ggplot(aes(x= zone, y= effort, fill=creelyear)) +
geom_bar(position="dodge", stat="identity", color = "black") + #Select data for plotting
scale_y_continuous(labels = comma, name = "Pressure (h/km)",
limits = c(0,12000), expand = c(0, 0)) + #Change y axis name and expand so bars touch y axis
scale_fill_manual(name = "", labels = c("2013-2014", "2022-2023"), values = c("#000000","#d11141"))+
scale_x_discrete(limit = c("Zone 1", "Zone 2", "Zone 3", "Zone 4", "Zone 5", "Total")) +
xlab("Zone") + #Change name of x axis
theme(legend.position = 'top', #Select legend position
legend.spacing.x = unit(1.0, 'cm'), #Select legend spacing value and units
legend.background = element_blank(),
legend.box.background = element_rect(colour = "black"),
legend.text = element_text(margin = margin(r = 6.2, unit = "cm"), hjust = 2),
panel.background = element_rect(fill='transparent'), #Set panel background to transparent for presentations
plot.background = element_rect(fill='transparent', color = "transparent"), #Set plot background to transparent for presentations
panel.grid.major = element_blank(), #Remove major gridlines
panel.grid.minor = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, size=1))
How can I center the text in legend and give some more space between the colors and text so it looks more aesthetically pleasing?
hjust = 2
in yourlegend.text
customization and see if you like the look of that. If you want to try centering the text, sethjust = 0.5
.hjust
(which stands for "horizontal justification") is the way to set the justification of the text.