Home > Blockchain >  How to correct plot width correct labels position in R (ggplot2)
How to correct plot width correct labels position in R (ggplot2)

Time:01-03

I need your help, I'm making my project in R markdown and I'm having some problems with it.

This plot is very strange, because of some long names like the second one the plot is very slim and makes it look weird and the tittle is incomplete. I tried using out.with = "100%" in the plot but it still is very strange

Other problem I have is that here the first bar is very long so I can't put the labels on the right. But the bottom bars are very short and I can't put them inside the bars. How can I solve this

enter image description here

Here is the dataset: enter image description here

You can apply these same principles for the other plot you used in your question.

collegeData %>%
  group_by(Major_category) %>% 
  summarize(Total = sum(Total)) %>% 
  ggplot(aes(x = reorder(Major_category, Total), y = Total, label = Total))  
  geom_col(fill = "darkblue")  
  geom_text(hjust = 0, nudge_y = 100000)  
  labs(title= "Number of students per Major Category")  
  ylab("Total of students")   xlab("Major category")  
  theme(axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)),
        axis.title.y = element_text(margin = margin(t = 0, r = 25, b = 0, l = 0)),
        plot.title = element_text(hjust = 0.5),
        plot.title.position = "plot")   
  scale_y_continuous(labels = comma,
                     expand = expansion(mult = c(0, .25)))  
  coord_flip()

enter image description here

  • Related