Reputation: 185
I visited this website to try to find the solution of the overlap problem. The picture is extracted from https://rstudio-pubs-static.s3.amazonaws.com/3364_d1a578f521174152b46b19d0c83cbe7e.html However, I still do not know how to solve it.
I noted some solution of the axis.text.x overlap such as using scale_x_discrete(labels = abbreviate)
to cut the words or using
axis.text.x = element_text(angle = 90, hjust = 1)
,but it does not my expectation. Can you share your problem-solving suggestions? Thanks.
Upvotes: 0
Views: 1140
Reputation: 13691
The task can be formulated as fitting some amount of text onto some amount of plotting space. This can be approached by manipulating either the size of the text, or the size of the plotting area. The text size can be modified in theme
:
ggplot(...) + theme( axis.text.x = element_text(size=10) )
while the plotting area size is specified as a parameter to ggsave
:
ggsave(..., width=10)
Stretching the plot this way can lead to undesirable effect of bars stretching out. This can be compensated for by specifying a different width
value in geom_bar
:
ggplot(...) + geom_bar( ..., width=0.5 )
Upvotes: 2