Hi Anitha,
There are 2 functions used to edit legend and all legends together.
Legend.background / text / title / direction / position, etc provide design and formating to each legends for all geom_* layers in the plot whereas
legend.box.background / text / title / direction / position provides format, edit the legends for all legends together.
An example -
ggplot(mpg, aes(displ, hwy, col = class)) + geom_point(size = 2,aes(shape = factor(cyl))) + theme(legend.box.background = element_rect(color = "red",fill = "grey"),legend.box.margin = margin(0.4,0.4,0.4,0.4,"cm"),legend.background = element_rect(color = "yellow")) + guides(shape = guide_legend(title = "cyl")) + scale_shape_discrete(labels = c("a","b","c","d")) + theme(legend.position = "bottom", legend.direction = "vertical")
The above code gives the below plot.
Here legend.key.background provides background color to the container that holds all legends whereas legend.background give color for each legend container.