. Advertisement .
..3..
. Advertisement .
..4..
To create a bar chart that is stacked by a factor, I am using ggplot. I also employ the following code.
ggplot(X) +
geom_bar(aes(X$Decade, fill=factor(X$Motivation)),
position='fill') +
theme(legend.position = "bottom")+
theme(axis.title.x = element_text(size = 20),
axis.title.y = element_text(size = 20))+
theme(text = element_text(size=20))+
theme(legend.text = element_text(size = 16),legend.title = element_blank())+
xlab("Decade")+
ylab("Percentage")+
scale_y_continuous(labels=percent)
However, it showed this warning: position_dodge requires non-overlapping x intervals.
I have no idea what the issue is.
Please help me solve it as soon as possible. Thanks a lot.
Solution:
Consider making your decade variable (x) become a factor. You shouldn’t use X$Decade because you’ve already loaded X as the dataset in ggplot.
That may be helpful for users to fix the position_dodge requires non-overlapping x intervals issue.