Katherine Xu
Katherine Xu

Reputation: 1

how to add x-axis and y-axis value in the bar chart using ggplot

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.

Upvotes: 0

Views: 46

Answers (1)

Ian Campbell
Ian Campbell

Reputation: 24770

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)

Upvotes: 1

Related Questions