I am going to provide my code below. there is my plot and at the sample plot i need to recreate. I don’t know how to add exactly same grey thick borders.
Current plot
Desired
ggplot(data = melted_df, aes(sample = value, color = Distribution)) +
stat_qq() +
geom_qq_line() +
facet_wrap(~Distribution, scales = "free") + xlab('Theoretical Quantiles') +
ylab('Sample Quantiles') +
ggtitle('QQ Plot for Different Distributions against Qnorm!') +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), plot.title = element_text(size = 11),
panel.background = element_rect(fill = "white"), legend.background=element_rect(fill = "lightgray"),
legend.key = element_rect(fill = "lightgray"),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
legend.box.background = element_rect(color = "gray45", fill = NA, size=3),
panel.border = element_rect(color = "gray45",fill = NA, size = 2),
strip.text = element_text(size = 10))
>Solution :
You are looking for strip.background
. As the docs state:
strip.background
background of facet labels (element_rect()
; inherits fromrect
).
In your case to match your other borders you can set it to element_rect(color = "gray45",fill = "grey90", size = 2)
Here’s an example with the iris
dataset:
ggplot(iris, aes(sample = Sepal.Length, color = Species)) +
stat_qq() +
geom_qq_line() +
facet_wrap(~Species, scales = "free") + xlab('Theoretical Quantiles') +
ylab('Sample Quantiles') +
ggtitle('QQ Plot for Different Distributions against Qnorm!') +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), plot.title = element_text(size = 11),
panel.background = element_rect(fill = "white"), legend.background=element_rect(fill = "lightgray"),
legend.key = element_rect(fill = "lightgray"),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
legend.box.background = element_rect(color = "gray45", fill = NA, size=3),
panel.border = element_rect(color = "gray45",fill = NA, size = 2),
strip.text = element_text(size = 10),
legend.position = "bottom", # I prefer the legend at the bottom
strip.background = element_rect(color = "gray45",fill = "grey90", size = 2)
# ^^ the line above is the only thing you need to add
)