简体   繁体   English

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

[英]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.我想在每个栏中添加 x 和 y 值。

I think you have two problems:我认为你有两个问题:

  1. Typo in geom_text geom_text中的错字
  2. You need to use the name of your data.frame in your call to rownames instead of "data".您需要在调用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过在 x 轴上使用两个变量和在 y 轴上使用分组变量来制作条形图? - How to make a bar-chart by using two variables on x-axis and a grouped variable on y-axis? R:在ggplot中,如何在y轴上为x轴上的每个多个日期添加多个文本标签 - R: In ggplot, how to add multiple text labels on the y-axis for each of multiple dates on the x-axis 如何使用 ggplot 在 x 轴上绘制日期,在 y 轴上绘制价格表和属性? - How can I plot date on x-axis and price list on y-axis and attribute by using ggplot? ggplot:在x轴上绘制bin,在y轴上绘制平均值 - ggplot: Plotting the bins on x-axis and the average on y-axis R中x轴和y轴ggplot的标签尺寸 - Size of labels for x-axis and y-axis ggplot in R Ggplot条形图:如何在y轴上显示百分比 - Ggplot bar chart: how to show precentage on the y-axis 添加自定义的x轴以绘制ggplot2和y轴 - Add a customized x-axis to plot ggplot2 and y-axis as well 使用 R 中的 ggplot package 更改 x 轴和 y 轴间距 - Change the x-axis and y-axis spacing using the ggplot package in R 使用带有数字 x 轴的 ggplot 在 R 中绘制类别变量在 y 轴上的比例 - Plotting the proportion of a categorial variable on the y-axis in R using ggplot with a numerical x-axis 使用r中的ggplot在y轴上使用相同的x轴绘制多个变量 - Plot multiple variables on y-axis with the same x-axis using ggplot in r
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM