I have a dataset and want to create a stack histogram. I have the code below for both data and the histogram itself. However, when I run this code, I do get values of 200, which is not what I want. I understand my code is adding the values of the different groups. but what i do want is for them to reflect the actual values instead.
bar graph for total LE
library
#library(ggplot2)
#library(viridis)
#library(hrbrthemes)
#dataset
group <- c(rep("Men 45" , 4) , rep("Men 65" , 4) , rep("Women 45" , 4) , rep("Women 65" , 4) )
pa <- rep(c("No activity" , "Inactive" , "Active", 'Very active') , 4)
value <- c(48.84,50.70, 51.06 , 51.15,51.11,52.38,52.80,52.90,29.17,30.44,30.86,30.99,30.24,31.69,32.17,32.29)
data <- data.frame(group,pa,value)
ggplot(data = data, aes(x=group, y=value, group = pa)) +
geom_col(aes(fill = pa), position = position_stack(reverse = TRUE)) +
geom_hline(yintercept = 0)
You didn't tag your question with the programming language - you would have likely gotten an answer a lot sooner with that tag! (I added it now.)
You wrote that you were looking for a histogram that shows actual values, but a histogram bins a continuous value. Your code calls a bar graph which defaults to a total count when nothing else is specified. You wrote that you wanted the actual values, you could sum the values, or you could choose another type of plot.
Two options come to mind. The first is simply because you mentioned a histogram. I couldn't find a meaningful way to represent the three variables, though.
Another option that gets all of your variables and all of your values into a meaningful graph. This graph dodges, like an extreme version of
geom_jitter()
.