如何使用ggplot在条形图中添加x轴和y轴值

时间:2020-05-01 19:46:23

标签: r ggplot2

这是我的代码:

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"

我想在每个小节内添加x和y值。

1 个答案:

答案 0 :(得分:1)

我认为您有两个问题:

  1. geom_text中的错字
  2. 您需要在对rownames的调用中使用data.frame的名称,而不是“ 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)