ggplot2:如何在条形图上定位axis.text.y

问题描述 投票:1回答:1

我制作了以下图表:使用ggplot的Likert-style bar chart。 y轴文本(带有国家名称)突出显示在图表标题的左侧,而我希望它看起来更接近条形。我试图在主题中使用vjust参数(axis.text.y = element_text(vjust = 1.5)),但它的参考点是文本的中间部分。因此标签看起来彼此错误。我希望他们只需向右移动几个点并保持一致。

我的代码:

p <- dane_1long %>% 
  ggplot() +
  geom_segment(aes(x = Kraj, y = start, xend = Kraj, yend = start + value, 
  colour = variable), size = 6) +
  geom_text(aes(label = scales::percent(round((value), digits = 2)),
            x = Kraj, y = (start + value)-value/2), 
            size = 3, family = "ING Me") +
  coord_flip() +
  theme_classic() +
  scale_color_manual("", labels = c("Zdecydowanie\nsię nie zgadzam", "Nie 
                     zgadzam się", "Ani się zgadzam,\nani się nie zgadzam", 
                     "Zgadzam się", "Zdecydowanie\nsię zgadzam"), 
                     values = ING_Likert_palette, guide = "legend") +
  scale_y_continuous(breaks = seq(- 75, 75, 25), limits=c(- 0.75, 0.75)) +
  labs(title = tresc_pytania, 
       subtitle = "Próba: 14 806 osób", 
       caption = "Źródło: Barometr finansowy ING", 
       y= " Percent",x= "") +
  theme(plot.title = element_text(face = "bold"),
       plot.subtitle = element_text(size = 7),
       plot.caption = element_text(size = 7, face = "italic"),
       legend.position = "top",
       legend.text = element_text(family = "ING Me",
                             size = 8,
                             color = grey(.3)),
       axis.title.x = element_blank(),
       axis.title.y = element_blank(),
       axis.line = element_blank(),
       axis.ticks = element_blank(),
       text = element_text(family = "ING Me",
                        size = 14,
                        color = grey(.3))); p 
r ggplot2 axis
1个回答
0
投票

这个巨大的空间是因为对称的情节,数据更多地位于积极的网站上。通过更改限制更改y轴刻度。

scale_y_continuous(breaks = seq(- 50, 75, 25), limits=c(- 0.51, 0.76))
© www.soinside.com 2019 - 2024. All rights reserved.