0
votes

Plot

I am a newbie to R and hence having some problems in plotting using ggplot and hence need help.

In the above diagram, if any of my bars have high values (in this case, a green one with value of 447), the plot and the plot title gets overlapped. The values here are normalised / scaled such that the y-axis values are always between 0-100, though the label might indicate a different number (this is the actual count of occurrences, where as the scaling is done based on percentages).

I would like to know how to avoid the overlap of the plot with the plot title, in all cases, where the bar heights are very close to 100.

The ggplot function I am using is as below.

my_plot<-ggplot(data_frame,
           aes(x=as.factor(X_VAR),y=GROUP_VALUE,fill=GROUP_VAR)) +
  geom_bar(stat="identity",position="dodge")  +
  geom_text(aes(label = BAR_COUNT, y=GROUP_VALUE, ymax=GROUP_VALUE, vjust = -1), position=position_dodge(width=1), size = 4) + 
  theme(axis.text.y=element_blank(),axis.text.x=element_text(size=12),legend.position = "right",legend.title=element_blank()) + ylab("Y-axis label") + 
  scale_fill_discrete(breaks=c("GRP_PERCENTAGE", "NORMALIZED_COUNT"),
                      labels=c("Percentage", "Count of Jobs")) +
  ggtitle("Distribution based on Text Analysis 2nd Level Sub-Category") + 
  theme(plot.title = element_text(lineheight=1, face="bold"))

Here is the ggsave command, in case if that is creating the problem, with dpi, height and width values.

ggsave(my_plot,file=paste(paste(variable_name,"my_plot",sep="_"),".png",sep = ""),dpi=72, height=6.75,width=9)

Can anyone please suggest what need to be done to get this right?

Many Thanks

1
Thanks @Jota I tried providing values for both hjust and vjust. But still the plots doesn't change much. hjust = 1,vjust=2greenhorntechie

1 Answers

2
votes

As Axeman suggests ylim is useful Have a look at the documentation here:

http://docs.ggplot2.org/0.9.3/xylim.html

In your code:

my_plot + ylim(0,110)

Also, I find this intro to axis quite useful: http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/

Good luck!