element_markdown() not adding spacing between words in title

64 views Asked by At

I'm working on a graph with ggplot2 that has the element_markdown() associated with plot.title. The problem is that I can't increase the spacing between words in this title so they are very close to each other given the font family I chose. When I change to element_text() I can increase it by adding " " but lose features of markdown style features. Is there a way to resolve this and continue using element_markdown()? Thanks!

My code:

  tema_base = theme(plot.title = element_markdown(size = 30, family = "WillyWonka"),
                    plot.subtitle = element_markdown(size = 15, family = "Arial Nova", lineheight = 1.2),
                    axis.text.x = element_markdown(size = 12, hjust = 1),
                    axis.text = element_markdown(size = 15, color = "black"),
                    axis.line = element_line(color = "black"),
                    panel.grid.minor.y = element_blank(),
                    panel.grid.major = element_blank(),
                    panel.grid.minor.x = element_blank(),
                    plot.caption = element_markdown(hjust = -0.06, margin = unit(c(-5,0,0,0), "mm"))) 
    
      df %>% 
      {ggplot(., aes(x = reorder(country, -gradpc, sum))) + 
          geom_col(data = . %>% filter(sex == "_T"), 
                   aes(y = gradpc), fill = "#a9d297", width = 0.5) +
          geom_point(data = . %>% filter(sex != "_T"),
                     aes(y = gradpc, fill = sex, shape = sex), color = "black", size = 4, show.legend = F) +
          geom_flag(aes(image = iso2c), y = -5)  +
          expand_limits(y = -5) + 
          geom_hline(yintercept = 0) +
          coord_cartesian(clip = 'off') +
          scale_fill_manual(values = c("#ff9c9c", "#6fa8dc")) +
          scale_shape_manual(values = c(24, 23)) +
          scale_y_continuous(breaks = seq(0, 60, 10)) +
          labs(title = "A   Fantastica   Fabrica   de   Advogados -------------------------------------",
               x = "", y = "", color = "", fill = "", shape = "") +
          theme_minimal(base_size = 15) + 
          tema_base +
          theme(axis.text.x = element_markdown(angle = 90),
                axis.line = element_blank(),
                panel.grid.major.y = element_line(linewidth = 0.3, linetype = "dashed", color = "#d6d6d6"),
                legend.position = c(0.6, 0.85),
                legend.direction = "horizontal",
                legend.text = element_markdown(size = 15))} %>% 
        ggsave("2.png", ., width = 12, height = 7, units = "in", dpi = 300)

Current output: Current output

Desired output (greater spacing between words): Desired output

My data:

structure(list(year = c("2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021"), country = c("SVN", 
"SVN", "SVN", "AUT", "POL", "POL", "IRL", "NOR", "NZL", "LTU", 
"HUN", "DEU", "ITA", "DNK", "AUS", "ITA", "CHE", "CAN", "PRT", 
"NOR", "LVA", "KOR", "KOR", "EST", "LVA", "DEU", "AUT", "EST", 
"KOR", "GRC", "ISR", "FIN", "FIN", "ISR", "GBR", "IRL", "BRA", 
"BRA", "HUN", "ESP", "POL", "BRA", "TUR", "IRL", "TUR", "CHE", 
"HUN", "LUX", "COL", "FIN", "FRA", "SWE", "EST", "ESP", "COL", 
"LVA", "PRT", "ISL", "GBR", "GBR", "USA", "USA", "CHL", "AUT", 
"ISR", "DNK", "CHL", "CAN", "CZE", "CAN", "NLD", "NZL", "BEL", 
"NZL", "BEL", "CHE", "GRC", "DEU", "SVK", "SVK", "SVK", "USA", 
"GRC", "LUX", "PRT", "CZE", "BEL", "AUS", "ISL", "AUS", "DNK", 
"ITA", "FRA", "NLD", "COL", "FRA", "TUR", "CHL", "SWE", "LTU", 
"SWE", "NOR", "LTU", "NLD", "ISL", "LUX", "CZE", "ESP"), field = c("F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042", "F042", "F042", "F042", "F042", "F042", 
"F042", "F042", "F042"), sex = c("F", "M", "_T", "F", "_T", "M", 
"F", "_T", "F", "F", "F", "M", "M", "F", "F", "_T", "_T", "F", 
"M", "M", "F", "M", "_T", "M", "_T", "_T", "_T", "F", "F", "M", 
"M", "_T", "M", "_T", "F", "M", "_T", "M", "M", "M", "F", "F", 
"_T", "_T", "M", "M", "_T", "F", "M", "F", "F", "F", "_T", "F", 
"F", "M", "_T", "_T", "M", "_T", "M", "_T", "_T", "M", "F", "_T", 
"F", "M", "M", "_T", "M", "M", "_T", "_T", "M", "F", "F", "F", 
"F", "M", "_T", "F", "_T", "M", "F", "F", "F", "_T", "F", "M", 
"M", "F", "M", "_T", "_T", "_T", "F", "M", "_T", "M", "M", "F", 
"_T", "F", "M", "_T", "_T", "_T"), grad = c(234, 81, 315, 304, 
4768, 1237, 1151, 422, 772, 380, 400, 2079, 2940, 712, 7454, 
6032, 2091, 1272, 812, 165, 388, 1739, 3967, 86, 558, 6335, 570, 
257, 2228, 394, 1374, 655, 203, 2963, 14410, 641, 118683, 50179, 
95, 6146, 3531, 68504, 17857, 1792, 8453, 802, 495, 52, 9070, 
452, 20887, 267, 343, 8936, 11591, 170, 2943, 134, 7333, 21743, 
1322, 4589, 3504, 266, 1589, 1078, 1776, 663, 149, 1935, 1755, 
471, 2574, 1243, 817, 1289, 1071, 4256, 496, 283, 779, 3267, 
1465, 20, 2131, 279, 1757, 11967, 84, 4514, 366, 3092, 7871, 
5397, 20661, 28758, 9404, 1728, 345, 205, 78, 257, 585, 3642, 
50, 72, 428, 15082), pop = c(1049039, 1059938, 2108977, 4535712, 
37840001, 18307488, 2528521, 5391369, 2574270, 1482082, 5066978, 
41026519, 28866226, 2935188, 12938497, 59236213, 8670300, 19151093, 
4858749, 2719259, 1017998, 25857805, 51744876, 630915, 1893223, 
83155031, 8932664, 699153, 25887071, 5196048, 4613240, 5533793, 
2733808, 9289762, 34192765.534, 2477803, 212425503.376, 103838240.194, 
4663794, 23227282, 19532513, 108587263.182, 83614362, 5006324, 
41915985, 4302599, 9730772, 315274, 24963893, 2799985, 34939338, 
5156448, 1330068, 24171413, 26153485, 875225, 10298252, 368792, 
32783993.164, 66976758.699, 162719324, 330382026, 19678363, 4396952, 
4676522, 5840045, 9969851, 18892357, 5275103, 38043450, 8686536, 
2537060, 11554767, 5111330, 5700474, 4367701, 5482584, 42128512, 
2793295, 2666486, 5459781, 167662702, 10678632, 319456, 5439503, 
5426674, 5854293, 25688079, 179749, 12749582, 2904857, 30369987, 
32717344, 17475415, 51117378, 67656682, 41698377, 9708512, 10379295, 
1313598, 5222847, 2672110, 2795680, 8788879, 189043, 634730, 
10701777, 47398695), gradpc = c(22.306129705378, 7.64195641631869, 
14.9361515085276, 6.70236558229447, 12.6004224999888, 6.75679809267115, 
45.5206818531466, 7.82732549005642, 29.9890842840883, 25.6396069853085, 
7.89425176110889, 5.0674540533161, 10.1849129844684, 24.2573899866039, 
57.6110192706309, 10.182960210505, 24.1168125670392, 6.64191855785986, 
16.7121207537166, 6.06782950796522, 38.1140237996538, 6.72524214642349, 
7.66645957369769, 13.630996251476, 29.473548546579, 7.61830032869569, 
6.38107511935969, 36.7587638185061, 8.60661293044702, 7.58268591822093, 
29.7838395574477, 11.8363661235612, 7.42553975992462, 31.8953273506899, 
42.1434176936383, 25.869691819729, 55.870410150295, 48.3242010903219, 
2.03696818512996, 26.4602634092099, 18.0775510043178, 63.0865886040266, 
21.3563789436078, 35.794726829506, 20.1665307400029, 18.6398964904701, 
5.08695507406812, 16.4935897029251, 36.3324742659328, 16.1429436229123, 
59.7807548614688, 5.17798298363525, 25.7881551920654, 36.9692909553943, 
44.3191414069674, 19.4235767945385, 28.577665413509, 36.334844573635, 
22.3676230144299, 32.4634999100436, 0.81244191992833, 1.38899808066435, 
17.8063591976629, 6.049645299744, 33.97824280523, 18.4587618759787, 
17.8137065438591, 3.50935566165725, 2.82458939664306, 5.08628949267219, 
20.2036807307309, 18.5647954719242, 22.2765201583035, 24.3185237501785, 
14.3321415026189, 29.5120934331357, 19.5345844222359, 10.1024218467531, 
17.7568069251547, 10.6132190455903, 14.2679715541704, 1.9485550220943, 
13.7189857277599, 6.26064309325854, 39.1763732826326, 5.14127069361454, 
30.0121637232711, 46.5858112628819, 46.7318316096334, 35.4050822999531, 
12.5995875184217, 10.1811041275717, 24.057576311818, 30.8833867464664, 
40.418739787475, 42.5057793995869, 22.5524365132964, 17.7988140716106, 
3.32392517988939, 15.605992091949, 1.49343834885456, 9.61786752790866, 
20.9251416471127, 41.4387318337185, 26.4490089556344, 11.3434058576087, 
3.99933581123957, 31.8194414424279), iso2c = c("SI", "SI", "SI", 
"AT", "PL", "PL", "IE", "NO", "NZ", "LT", "HU", "DE", "IT", "DK", 
"AU", "IT", "CH", "CA", "PT", "NO", "LV", "KR", "KR", "EE", "LV", 
"DE", "AT", "EE", "KR", "GR", "IL", "FI", "FI", "IL", "GB", "IE", 
"BR", "BR", "HU", "ES", "PL", "BR", "TR", "IE", "TR", "CH", "HU", 
"LU", "CO", "FI", "FR", "SE", "EE", "ES", "CO", "LV", "PT", "IS", 
"GB", "GB", "US", "US", "CL", "AT", "IL", "DK", "CL", "CA", "CZ", 
"CA", "NL", "NZ", "BE", "NZ", "BE", "CH", "GR", "DE", "SK", "SK", 
"SK", "US", "GR", "LU", "PT", "CZ", "BE", "AU", "IS", "AU", "DK", 
"IT", "FR", "NL", "CO", "FR", "TR", "CL", "SE", "LT", "SE", "NO", 
"LT", "NL", "IS", "LU", "CZ", "ES")), row.names = c(NA, -108L
), class = c("tbl_df", "tbl", "data.frame"))
0

There are 0 answers