I posted following question on https://stats.stackexchange.com/questions/117578/density-distribution-of-outcomes-of-2-dice-rolled but did not get any response.
This question is related to: A histogram with a bar for each frequency value
Two dice are rolled and the sum is plotted. The histogram is as expected but density graph shows different densities of 2 and 12 and the plot is assymetric. Why is this so? Amongst the outcomes of 2 dice rolled, the chances of 2 are equal to that of 12. Why is it that the density graph is of unequal values?
num.dices <- 2L
num.rolls <- 100000L
outcomes <- matrix(sample(1:6, num.dices * num.rolls, replace = TRUE),
nrow = num.rolls, ncol = num.dices)
sums <- rowSums(outcomes)
Histogram:
ggplot(data.frame(sums), aes(x=factor(sums)))+geom_histogram()
Density plot:
ggplot(data.frame(sums), aes(x=factor(sums), fill=factor(sums)))+geom_density()
I also tried:
ggplot(data.frame(sums), aes(x=factor(sums), fill=factor(sums)))+geom_density(aes(y = ..count..))
plot(density(sums))
in ggplot(). You should be able to ajdust it somehow. – J.R.ggplot(data.frame(sums), aes(x=sums, fill=2))+geom_density()
, I'm not quite sure what you are trying to archive here. – J.R.