Search code examples
rdataframeggplot2plotbar-chart

my values in y axis doesn't match in ggplot


I have a dataset that looks like this: I want to plot common and unique values between two cases short only vs shortplus long case. I have used ggplot to plot a stack bar plot for better visualization. But in my plot the yaxis values doesn't match the value in my dataframe.

dput(datamine)
structure(list(specie = c("short_only", "short_only", "shortpluslong", 
"shortpluslong"), condition = c("common", "unique", "common", 
"unique"), value = c(9577, 556, 9577, 2342)), class = "data.frame", row.names = c(NA, 
-4L))

ggplot(datamine, aes(fill=condition, y=value, x=specie)) + 
     geom_bar(position="fill", stat="identity")

My plot looks like this: enter image description here


Solution

  • Your problem is the position argument in geom_bar.

    ggplot(datamine, aes(fill=condition, y=value, x=specie)) + 
    geom_bar(stat="identity")