ggplot2 geom_bar() , do not merge y-values shared same x-ids I am plotting a barplot using ggplot + geom_bar() function in R.
I have some the recoreds which share the same x-axis identifiers.
geom_bar() did merge all values that shared the same x-axis identifiers.
Like the following example.
library(&quot;ggplot2&quot;)

df &lt;- data.frame(x = c(&quot;a&quot;,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;),
                 y = c(5,5,5,5,5,5),
                 stringsAsFactors = FALSE)

ggplot(df, aes(x, y)) + geom_bar(stat = &quot;identity&quot;)


The erroneous graph is displayed below.
The highest bar means the sum of multiple y-values shared same x-axis names.
Anyone else could help me to solve this problem? Thanks.
As you seem to have surmised, the graph is not erroneous, but correct. You have a total of 10 for a and that's what it's showing. If you want it to ignore duplicate X-axis values then you need to tell ggplot which datapoints it should actually be using. barplot() is assuming that your duplicate a values are intentional, ggplot assumes they should be grouped. These are both reasonable assumptions and it's your responsibility to determine beforehand which is correct.