-1

Having a dataset like this:

df <- structure(list(word = structure(c(1L, 12L, 23L, 34L, 43L, 44L, 
45L, 46L, 47L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L, 25L, 26L, 27L, 
28L, 29L, 30L, 31L, 32L, 33L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 
42L), .Label = c("word1", "word10", "word11", "word12", "word13", 
"word14", "word15", "word16", "word17", "word18", "word19", "word2", 
"word20", "word21", "word22", "word23", "word24", "word25", "word26", 
"word27", "word28", "word29", "word3", "word30", "word31", "word32", 
"word33", "word34", "word35", "word36", "word37", "word38", "word39", 
"word4", "word40", "word41", "word42", "word43", "word44", "word45", 
"word46", "word47", "word5", "word6", "word7", "word8", "word9"
), class = "factor"), frq = c(1975L, 1665L, 1655L, 1469L, 1464L, 
1451L, 1353L, 1309L, 1590L, 1545L, 1557L, 1556L, 1130L, 1153L, 
1151L, 1150L, 1144L, 1141L, 1115L, 194L, 195L, 135L, 135L, 130L, 
163L, 167L, 164L, 159L, 153L, 145L, 143L, 133L, 133L, 153L, 153L, 
150L, 119L, 115L, 115L, 115L, 114L, 113L, 113L, 113L, 115L, 102L, 
101L)), .Names = c("word", "frq"), class = "data.frame", row.names = c(NA, 
-47L))

With this command lines I produce a bar plot graph

dat2 = transform(df,word = reorder(word,frq))
df2 <- head(dat2, 10)
p = ggplot(df2, aes(x = word, y = frq)) + geom_bar(stat = "identity", fill = "yellow")
p2 <- p +coord_flip()

How is it possible to have the number of frq in the end of every bar?

Sasak
  • 189
  • 5
  • 15

1 Answers1

2

I would use annotate..

p2 + annotate(geom = "text",x = df2$word, y= df2$frq, label = df2$frq)
Damiano Fantini
  • 1,925
  • 9
  • 11
  • Thank you. This work! But just a question do you know how could I go the numbers a little right because the half of number is in the bar and the second out? – Sasak Aug 26 '17 at 15:14
  • 1
    You can easy position your annotations by tuning your x and your y. For example, a simple fix in this case is to add a small fixed value (for example, 80) to your y. `p2 + annotate(geom = "text",x = df2$word, y = 80 + df2$frq, label = df2$frq)` – Damiano Fantini Aug 26 '17 at 15:42