I have a dataframe like shown below
Quarter X2013 X2014 Total.Result
1 Qtr 1 77282.13 66421.10 143703.2
2 Qtr 2 69174.64 76480.13 145654.8
3 Qtr 3 65238.47 79081.74 144320.2
4 Qtr 4 65429.73 109738.82 175168.5
And I generated a barplot by melting the data-frame as shown below. But the problem lies in annotating the bar values as shown in the flowing pic.
dfm <- melt(qtr2, id.vars = c('Quarter', 'Total.Result'))
#ggplot statement
{
ggplot(dfm, aes(x = factor(Quarter), y = value, fill = variable) ) +
geom_bar(stat="identity", position = 'dodge') + theme_bw() +
geom_text(aes(label=value,angle = 90), vjust=0)+
ylab("Sales ($)") +
xlab("Quarter")+
ggtitle(label1) +
theme(plot.title = element_text(size=20,lineheight=.8, face="bold"))+
scale_fill_discrete(name="Years",
breaks=c("X2013", "X2014"),
labels=c("2013", "2014")) +
theme(legend.background = element_rect(fill="gray90",
size=.5, linetype="dotted"))+
theme(axis.title.x = element_text(face="bold", colour="#990000", size=20),
axis.text.x = element_text(angle=90, vjust=0.5, size=16))+
theme(axis.title.y = element_text(face="bold", colour="#990000", size=20),
axis.text.y = element_text(angle=90, vjust=0.5, size=16))+
scale_y_continuous(labels=dollar)
}
The output plot
How do I set proper position and font styles to the
geom_text
?
The .csv file for the sample data to import into R
"Quarter","2013","2014","Total Result"
"Qtr 1", 77282.13, 66421.10, 143703.23
"Qtr 2", 69174.64, 76480.13, 145654.77
"Qtr 3", 65238.47, 79081.74, 144320.21
"Qtr 4", 65429.73, 109738.82, 175168.55