1

问题

我正在尝试复制hjust = 0ggrepel 示例中的面板中的文本对齐甚至间距: 在此处输入图像描述

我的情节

困难在于我将多个字符串连接成单个标签,这样线段就不会使情节看起来太混乱。这些较大的标签似乎并不能很好地相互配合: 在此处输入图像描述

数据

nest_data <- structure(list(rate = c(27, 25, 24, 23, 22, 21, 20, 19, 18, 17, 
16, 15, 10, 8, 7.7, 5), country_groups = c("Hungary", "Denmark\n Norway\n Sweden", 
"Finland\n Greece\n Iceland", "Ireland\n Poland\n Portugal", 
"Italy\n Slovenia", "Belgium\n Czech Republic\n Latvia\n Lithuania\n Netherlands\n Spain", 
"Austria\n Estonia\n France\n Slovak Republic\n United Kingdom", 
"Chile\n Germany", "Turkey", "Israel\n Luxembourg", "Mexico", 
"New Zealand", "Australia\n Korea", "Japan", "Switzerland", "Canada"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-16L))

我的尝试

(nest_data_vat_plot <- ggplot(nest_data, aes(y = rate, x = 1, label = country_groups)) +
    geom_point(color = "red") +
    theme(
      axis.line.x  = element_blank(),
      axis.ticks.x = element_blank(),
      axis.text.x  = element_blank(),
      axis.title.x = element_blank(),
      plot.title   = element_text(hjust = 0),
      panel.background = element_blank()
    ) +
    xlim(1, 1.1) +
    geom_text_repel(
      nudge_x      = 0.035,
      direction    = "y",
      hjust        = 0
    ) + 
    scale_y_continuous(breaks = seq(2.5, 30, 2.5)) + 
    labs(
      title = "Consumption tax rates",
      caption = "Source: OECD Tax Stats \n2019 data presented \nRef: oecd_vat_gst_rates.R",
      x = "",
      y = ""
    ))

4

0 回答 0