0

this is my code:

ggplot(data = samplesolution2, aes(x = transdt, y = transAmount, group = bankAcctID, fill = bankAcctID)) +
  geom_bar(stat = "identity") +
  geom_test(label = rownames(data), nudge_x = 0.25, nudge_y =  0.25, check_overlap = T) +
  ggtitle(label = "Showing Only Total Deposits Over $200") +
  facet_wrap(~ bankAcctID, ncol = 1) 

Error in geom_test(label = rownames(data), nudge_x = 0.25, nudge_y = 0.25,  : 
  could not find function "geom_test"

And I want to add x and y value inside each bar.

otwtm
  • 1,779
  • 1
  • 16
  • 27
  • 1
    Hi, welcome to Stackoverflow! Can you make the code example reproducible by providing a sample of the data? – otwtm May 01 '20 at 19:50
  • Hi Katherine, welcome to Stack Overflow. If my answer below doesn't fix your problem, please provide at least a sample of your data with `dput(samplesolution2)` or if your data is very large `dput(samplesolution2[1:10,])`. You can edit your question and paste the output. You can surround it with three backticks (```) for better formatting. See [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – Ian Campbell May 01 '20 at 19:58
  • > dput(samplesolution2[1:4, ]) structure(list(bankAcctID = c("775044", "775044", "775044", "775044" ), startdt = structure(c(1L, 1L, 1L, 1L), .Label = "2018-05-01", class = "factor"), amt = c(858.46, 858.46, 858.46, 858.46), transdt = structure(c(18334, 18348, 18362, 18376), class = "Date"), transAmount = c(373.73, 360.22, 351.21, 360.22), TtransAmount = c(-443.23, -274.03, -507.25, -498.24), EOD = c(415.23, 584.43, 351.21, 360.22 )), row.names = c(NA, 4L), class = "data.frame") – Katherine Xu May 01 '20 at 20:07

1 Answers1

1

I think you have two problems:

  1. Typo in geom_text
  2. You need to use the name of your data.frame in your call to rownames instead of "data".
ggplot(data = samplesolution2, 
       aes(x = transdt, y = transAmount, group = bankAcctID, fill = bankAcctID)) +
  geom_bar(stat = "identity") + 
  geom_text(label = rownames(samplesolution2), nudge_x = 0.25, nudge_y = 0.25, check_overlap = T) +
  ggtitle(label = "Showing Only Total Deposits Over $200") +
  facet_wrap(~ bankAcctID, ncol = 1)
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
  • I actually changed code to: geom_text(aes(x = transdt, y = transAmount, label = transdt)), but this can only show the transdt on the bar. How to show both transAmount and transdt? – Katherine Xu May 01 '20 at 20:11