How can we adjust margins or change distance to axis in ggplot?

1.1K    Asked by leahD’Costa in Data Science , Asked on Jun 1, 2020
Answered by leah D’Costa

In spite of the fact that there are such a large number of subject alternatives in ggplot2, there doesn't give off an impression of being a choice which sets a fixed edge space for the tomahawks (or if there is it is very much covered up). The cowplot bundle has an align_plots work which can adjust one or the two tomahawks in a rundown of plots. align_plots restores a rundown, every part of which is the first plot however with the tomahawks determined and adjusted. We are using the grid.arrange function from the gridExtra package to output both plots so we can see the way the alignment works:

library(ggplot2)

dat = data.frame(x = 1:5, y = 1e-5* (1:5) ^ 2)

p = ggplot(dat, aes(x, y)) + geom_point() + geom_line()

print(p)

p1 = p + scale_y_log10()

print(p1)

library(cowplot)

library(gridExtra)

p2 = align_plots(p, p1, align = "hv")

grid.arrange(p2[[1]], p2[[2]])




Your Answer

Interviews

Parent Categories