1
votes

I have produced the following chart:Likert-style bar chart using a ggplot. The y axis text (with countries' names) protrude on the left of the title of the chart, whereas I would like it to appear closer to the bars. I tried to use a vjust paramteter in the theme(axis.text.y = element_text(vjust = 1.5)), but its point of reference is the middle of the text. Therefore labels appear misalligned with each other. I would like them simply to move to the right by a couple of points and remain in line.

My code:

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 
1
Could you post some sample data?erocoar
I could, but I have no idea how to upload such file. In general, the code and chart is based on this site. : rnotr.com/likert/ggplot/barometer/likert-plotlyKarol Pogorzelski

1 Answers

0
votes

This huge space is because of the symmetrical plot and the data is more located on the positive site. Change the y axis scale a bit by changing the limits.

scale_y_continuous(breaks = seq(- 50, 75, 25), limits=c(- 0.51, 0.76))