Разрыв с осью X при вращении меток X - PullRequest
0 голосов
/ 30 мая 2018

Как объясняется в заголовке, когда я вращаю метку x, между осью x и метками появляется зазор.Кроме того, часть надписей находится за пределами области рисования.Я перепробовал несколько вещей, вот мой воспроизводимый код и скриншот полученного сюжета.Чего я не понимаю, так это того, что этот разрыв не существует, когда мои метки не повернуты (angle=90) См. Скриншот 2.

library(ggplot2)
library(ggthemes)

df <- data.frame(country=c("Malaysia", "Mongolia", "Kazakhstan", "China", 
                           "Indonesia", "Philippines", "Turkmenistan",
                           "Maldives", "Pakistan", "Bhutan", "Thailand" ,"Myanmar", 
                           "India", "Bangladesh", "Afghanistan", "Nepal"),
                 Urbanization_Rate=c(72.8, 68.5, 53.6, 50.6, 50.7, 48.8, 
                                     48.7, 41.2, 36.2, 35.6, 34.1, 32.6, 31.3, 
                                     28.4, 23.5, 17))

ggplot(df, aes(x = reorder(country, -Urbanization_Rate),
               y = Urbanization_Rate)) + 
  geom_bar(stat = "identity", fill="darkseagreen3") +
  theme(axis.text.x=element_text(angle=60,vjust = 0.3, hjust=1,size=15)) + 
  theme(axis.text.y = element_text(size=13)) + 
  scale_y_continuous(expand = c(0, 0), limits = c(0, 80),
                     breaks=c(10,20, 30, 40,50,60,70,80)) +
  theme_hc() +
  theme(axis.title.x = element_blank())

enter image description here

enter image description here

1 Ответ

0 голосов
/ 30 мая 2018

Вы можете изменить аргумент vjust на 1, чтобы снова выровнять его по оси x.

ggplot(df, aes(x = reorder(country, -Urbanization_Rate),
           y = Urbanization_Rate)) + 
  geom_bar(stat = "identity", fill="darkseagreen3") +
  theme(axis.text.x=element_text(angle=60,vjust = 1, hjust=1,size=15)) + 
  theme(axis.text.y = element_text(size=13)) + 
  scale_y_continuous(expand = c(0, 0), limits = c(0, 80),
                 breaks=c(10,20, 30, 40,50,60,70,80)) +
  theme_hc() + 
  theme(axis.title.x = element_blank())

enter image description here

...