leombastos / 2024_ppa

1 stars 4 forks source link

Issue merging maps #32

Open Vincius-Trevisan opened 4 months ago

Vincius-Trevisan commented 4 months ago

Hello everyone.

For the assignment 4, I ran into a problem. It is not an error itself.

When I plot my soil-type map the legend is quite big, and takes half of the map space, I have been trying to change different features but it is not solving. The same problem happens when all the plots are merged, the legends keep covering the map view, even when the size is changed.

Capture PNG02 Soil type map.

Capture PNG01 Merging all maps

Soil type ggplot code: series_map <- ggplot()+ geom_sf(data = boundary_geoj, alpha = 0.5) + geom_sf(data = series_sf, aes(fill = muname))+ scale_fill_viridis_d()+ theme(legend.position = "bottom", legend.box = "horizontal" )+ guides(fill = guide_legend(nrow = 4, byrow = TRUE))+ labs(fill = "Soil type")+ theme_map()

series_map

Merging code:

| fig-width: 15

| fig-height: 20

series_map + yield_map + elevation_map + plot_annotation(title = "Soil series(a), corn yield (b), and elevation (c)", tag_levels = "a", tag_suffix = ")" ) & theme(plot.title = element_text(hjust = 0.5, size = 30))

ggsave("../output/series_map.png", width = 15, height = 20, limitsize = FALSE )

Does someone have ideas on how to make it look better?

leombastos commented 4 months ago

@Vincius-Trevisan what happens if you do theme(legend.position = "left")?

Vincius-Trevisan commented 4 months ago

for some reason, it doesn't move at all. Capture 111 22222

ClintHerndon commented 4 months ago

I am also having issues with the legend being to large or not even showing at all and the actual field maps being small when I combine the maps

combining maps legend problem

series_map + yield_map + elevation_map + plot_annotation(title = "Soil Series (a), Corn Yield (b), and Elevation (c)", tag_levels = "a", tag_suffix = ")") + theme(plot.title = element_text(hjust = 0.5, size = 20), legend.position = "top")

leombastos commented 4 months ago

@Vincius-Trevisan @ClintHerndon if the issue persists when you render it, and none of the potential fixes worked (e.g., changing the size of the figure output at the chunk level as we discussed in class, moving the legend to the right or left, etc), then please send me the rendered version (with the legends overlapping) and the individual figures (png files) for the maps that were overlapping.

NivaIbrahim commented 4 months ago

I was having the same issue and tried different ways. Finally I gave up and made changes in 2 places: 1) in static map (elevation and yield) used : theme(legend.position=" right") 2) in combined plot chunk I used:

legend.key.size=unit(.5,"lines)+ theme(plot.margin= margin(t=1, unit="lines")

Overall maps became small, but according to ratio, all are same now.

I know it is not a great solution to offer, but at least it helps.