I am trying to make a nice figure of multiple boxplots but I am having trouble getting reasonable width and spacing between them. Can someone please help me widen each boxplot (ideally all being the same width) but prevent them from overlapping? This is what I've tried so far:
library(ggplot2)
library(ggExtra)
library(ggpattern)
structure(list(Data = c("South_Africa", "Lesbos", "Costa_Rica",
"Lesbos", "South_Africa", "Lesbos", "Lesbos", "Lesbos", "Lesbos",
"Lesbos", "Costa_Rica", "South_Africa", "South_Africa", "Costa_Rica",
"Lesbos", "Lesbos", "Lesbos", "Lesbos", "Lesbos", "Lesbos", "Lesbos",
"Costa_Rica", "South_Africa", "Costa_Rica", "Lesbos", "South_Africa",
"Lesbos", "South_Africa", "Lesbos", "Lesbos", "Lesbos", "Costa_Rica",
"South_Africa", "Costa_Rica", "Costa_Rica", "Costa_Rica", "Lesbos",
"Costa_Rica", "South_Africa", "Lesbos"), Soil = c("NU", "NU",
"NU", "NU", "NU", "NU", "NU", "U", "NU", "NU", "NU", "NU", "NU",
"NU", "NU", "NU", "U", "NU", "NU", "U", "NU", "NU", "NU", "NU",
"U", "NU", "U", "U", "U", "U", "NU", "NU", "NU", "NU", "NU",
"NU", "U", "NU", "NU", "U"), Taxa = c("Gisekia africana", "Dactylis_glomerata",
"piper", "Crepis_commutata", "Ruellia patula", "Hordeum_bulbosum",
"Bromus_commutatus", "Torilis_nodosa", "Lagoecia_cuminoides",
"Aegilops_biuncialis", "guamac", "Celtis africana", "Ziziphus mucronata",
"exomex", "Trachynia_distachya", "Lolium_rigidum", "Trifolium_angustifolium",
"Plantago_lagopus", "Torilis_nodosa", "Lolium_rigidum", "Trifolium_arvense",
"bauung", "Senecio latifolius", "mactin", "Aegilops_biuncialis",
"Geigeria ornativa", "Trachynia_distachya", "Faurea saligna",
"Lagoecia_cuminoides", "Cynosurus_echinatus", "Phleum_pratense",
"casser", "Polygala hottentotta", "luespe", "steobo", "chospi",
"Hordeum_bulbosum", "calcan", "Combretum apiculatum", "Dactylis_glomerata"
), SLA = c(39.35278345, 39.2, 38.7204594, 38.193, 37.16119821,
36.5482, 36.423, 36.3955172, 35.7273333, 34.58675, 34.236364,
33.88607569, 33.8744023, 33.8530125, 33.366, 32.9338, 32.7803704,
32.579, 31.9593878, 31.7509091, 31.3455, 31.3426755, 30.89855185,
30.2421874, 30.2008955, 29.9203306, 29.7844828, 29.43251529,
29.36, 29.1293333, 29.09, 29.0699486, 28.72968653, 28.7162493,
28.5190057, 28.1025365, 27.94175, 27.8320321, 27.29171929, 27.266
), Clim = c("Subtropical", "Meditteranean", "Tropical", "Meditteranean",
"Subtropical", "Meditteranean", "Meditteranean", "Meditteranean",
"Meditteranean", "Meditteranean", "Tropical", "Subtropical",
"Subtropical", "Tropical", "Meditteranean", "Meditteranean",
"Meditteranean", "Meditteranean", "Meditteranean", "Meditteranean",
"Meditteranean", "Tropical", "Subtropical", "Tropical", "Meditteranean",
"Subtropical", "Meditteranean", "Subtropical", "Meditteranean",
"Meditteranean", "Meditteranean", "Tropical", "Subtropical",
"Tropical", "Tropical", "Tropical", "Meditteranean", "Tropical",
"Subtropical", "Meditteranean"), AnnTemp = c(18.9, 15.6, 25.8,
15.6, 18.9, 15.6, 15.6, 15.1, 15.6, 15.6, 25.8, 18.9, 18.9, 25.8,
15.6, 15.6, 15.1, 15.6, 15.6, 15.1, 15.6, 25.8, 18.9, 25.8, 15.1,
18.9, 15.1, 19.3, 15.1, 15.1, 15.6, 25.8, 18.9, 25.8, 25.8, 25.8,
15.1, 25.8, 18.9, 15.1), AnnPrecip = c(716, 620.5, 1662, 620.5,
716, 620.5, 620.5, 636.5, 620.5, 620.5, 1662, 716, 716, 1662,
620.5, 620.5, 636.5, 620.5, 620.5, 636.5, 620.5, 1662, 716, 1662,
636.5, 716, 636.5, 699, 636.5, 636.5, 620.5, 1662, 716, 1662,
1662, 1662, 636.5, 1662, 716, 636.5)), row.names = c(NA, 40L), class = "data.frame")
dodge <- position_dodge2(padding = 0.5,
preserve = c("total", "single"))
ClimFigP <- ggplot(ClimDF, aes(x = AnnPrecip, y = SLA, fill = Data, pattern = Soil, alpha=0.4)) +
geom_boxplot_pattern(
color = "black",
pattern_fill = "black",
pattern_angle = 45,
pattern_density = 0.3,
pattern_spacing = 0.025,
pattern_key_scale_factor = 0.6,
width = 75,
position = dodge) +
scale_pattern_manual(values = c(U = "circle", NU = "none")) +
scale_fill_manual(values = c('lightblue','lightskyblue','palegreen1','lemonchiffon2','lightsalmon')) +
theme_classic()
ClimFigP
Also if you could help me get rid of the uneccessary alpha key and remove the stripes in the Data key that would be much appreciated!