r - Add an arrow pointing at the x-axis in my plot in ggplot2 -


my goal arrow text pointing @ x-axis label average word frequency. cannot figure out life of me how either arrow or text outside of plotting area in ggplot2.

here code:

ggplot(summary.pctdiff, aes(principle, pctdiff)) +xlab("principle")+ylab("% difference")+     geom_bar(aes(fill = sector),position = "dodge", stat="identity",col="black")+     ggtitle("how differing sectors talk different co-operative principles")+theme(plot.title=element_text(hjust=0.5),panel.border = element_rect(colour = "black", fill=na, size=1),legend.background = element_rect(color = "black"),legend.position =c(1.10,0.7),plot.margin=unit(c(0.5,3,0.5,0.5),"cm"))+     geom_hline(yintercept = 0) 

here data:

structure(list(principle = structure(c(1l, 2l, 3l, 4l, 5l, 6l,  7l, 1l, 2l, 3l, 4l, 5l, 6l, 7l, 1l, 2l, 3l, 4l, 5l, 6l, 7l, 1l,  3l, 4l, 5l, 6l, 7l), .label = c("principle 1", "principle 2",  "principle 3", "principle 4", "principle 5", "principle 6", "principle 7" ), class = "factor"), pctdiff = c(-6.71369900758148, 9.44233503731219,  11.0107840625484, -53.1259224412594, -9.22356636157099, -41.0142340880256,  -9.6288000905822, -55.3759198976217, -19.1012386886889, -75.4996296064581,  -44.7688906852688, -58.5771031808126, 48.9559446961189, 4.52522805921763,  29.4368505336144, 51.7181015822617, -2.26377179780978, 48.1990295720174,  57.4736669182075, 8.41689226435695, -15.8983115124042, 30.6261564806236,  79.5018869249509, 87.2542807992621, -15.3228747516659, 13.5915020818539,  48.2301858238767), sector = c("ag", "ag", "ag", "ag", "ag", "ag",  "ag", "fin", "fin", "fin", "fin", "fin", "fin", "fin", "serv",  "serv", "serv", "serv", "serv", "serv", "serv", "other", "other",   "other", "other", "other", "other")), .names = c("principle",   "pctdiff", "sector"), row.names = c(na, -27l), class = "data.frame") 

df <- structure(list(principle = structure(c(1l, 2l, 3l, 4l, 5l, 6l,  7l, 1l, 2l, 3l, 4l, 5l, 6l, 7l, 1l, 2l, 3l, 4l, 5l, 6l, 7l, 1l,  3l, 4l, 5l, 6l, 7l), .label = c("principle 1", "principle 2",  "principle 3", "principle 4", "principle 5", "principle 6", "principle 7" ), class = "factor"), pctdiff = c(-6.71369900758148, 9.44233503731219,  11.0107840625484, -53.1259224412594, -9.22356636157099, -41.0142340880256,  -9.6288000905822, -55.3759198976217, -19.1012386886889, -75.4996296064581,  -44.7688906852688, -58.5771031808126, 48.9559446961189, 4.52522805921763,  29.4368505336144, 51.7181015822617, -2.26377179780978, 48.1990295720174,  57.4736669182075, 8.41689226435695, -15.8983115124042, 30.6261564806236,  79.5018869249509, 87.2542807992621, -15.3228747516659, 13.5915020818539,  48.2301858238767), sector = c("ag", "ag", "ag", "ag", "ag", "ag",  "ag", "fin", "fin", "fin", "fin", "fin", "fin", "fin", "serv",  "serv", "serv", "serv", "serv", "serv", "serv", "other", "other",   "other", "other", "other", "other")), .names = c("principle",   "pctdiff", "sector"), row.names = c(na, -27l), class = "data.frame")  library(ggplot2) library(grid) p <- ggplot(df, aes(principle, pctdiff)) +xlab("principle")+ylab("% difference")+     geom_bar(aes(fill = sector),position = "dodge", stat="identity",col="black")+     ggtitle("how differing sectors talk different co-operative principles")+theme(plot.title=element_text(hjust=0.5),panel.border = element_rect(colour = "black", fill=na, size=1),legend.background = element_rect(color = "black"),legend.position =c(1.10,0.7),plot.margin=unit(c(0.5,3,0.5,0.5),"cm"))+     geom_hline(yintercept = 0)   # add text in bottom right corner outside plotting area p <- p + annotation_custom(   grob = grid::textgrob(label = "text", hjust=0, gp=gpar(col="blue", cex=1.7)),   xmin = 8, xmax = 8, ymin =-90, ymax = -90 )  # add arrow in bottom right corner outside plotting area p <- p + annotation_custom(   grob = linesgrob(arrow=arrow(type="open", ends="first", length=unit(3,"mm")), gp=gpar(col="red", lwd=3)),    xmin = 8.25, xmax = 8.5, ymin = -85, ymax = -60 )   # turn off panel clipping gt <- ggplot_gtable(ggplot_build(p)) gt$layout$clip[gt$layout$name == "panel"] <- "off" grid.draw(gt) 

enter image description here


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -