I created this script to display some environmental impacts for my research.
`legend_plot <- ggplot(data_longGW, aes(x = Crop_cycleGW, y = kg_CO2_eq, fill = Category)) +
geom_bar(stat = "identity", colour = "grey30") +
scale_fill_manual(values = custom_colors) +
theme_minimal() +
theme(legend.position = "bottom",
legend.title = element_blank(),
legend.background = element_rect(fill = "white", size = 0.5, linetype = "solid", colour = "black"))
legend <- get_legend(legend_plot)
combined_plot <- plot_grid(
plot_grid(GW, TA, FE, ME, ET, FRS, ncol = 3),
legend,
ncol = 1,
rel_heights = c(1, 0.1)
)
print(combined_plot)`
When I plot the combined plot part, I get this error and the legend is not displayed in the picture:
In get_plot_component(plot, "guide-box") : Multiple components found; returning the first one. To return all, use
return_all = TRUE`
When I plot the code, the graph is displayed without the legend.
Is there a way to fix this?
Thanks for your help 🙂
I tried to add the suggestions from RStudio but it didn’t worked
Guido Evangelista is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.