Reputation: 11
Am trying to plot histogram for the following function which simulates a die experiment
rm(list=ls())
roll<-function()
{
sample(1:6,size = 2,replace = 2)
}
rolls<-replicate(10000,roll())
qplot(rolls,aes(x=rolls),binwidth=1)
am getting the following error "Error: stat_bin requires the following missing aesthetics: x"
please help.
Upvotes: 0
Views: 310
Reputation: 41
Check ?qplot
. The first and the second arguments are x
and y
. Anyway, if you are simulating the die experiment 10,000 times, you don't need to define your function and use replicate
. Just specify size = 10000
in sample()
.
rm(list=ls())
rolls <- sample(1:6,size = 10000 ,replace = TRUE)
qplot(rolls, binwidth = 1)
Upvotes: 1