You can use Pearson's chi-squared test to do this. See
A test of homogeneity compares the distribution of counts for two or more groups using the same categorical variable (e.g. choice of activity—college, military, employment, travel—of graduates of a high school reported a year after graduation, sorted by graduation year, to see if number of graduates choosing a given activity has changed from class to class, or from decade to decade).[3]
Code example:
#fake data
nl <- c(20,25,30,20) # sample size
pl1 <- c(0.2,0.3,0.4,0.5) # diffrent p
pl2 <- c(0.3,0.3,0.3,0.3) # same p
tab1 <- sapply(1:4,function(i){
s <- sum(rbinom(nl[i],1,pl1[i]))
return(c(nl[i]-s,s))
})
tab2 <- sapply(1:4,function(i){
s <- sum(rbinom(nl[i],1,pl2[i]))
return(c(nl[i]-s,s))
})
tab1
# [,1] [,2] [,3] [,4]
#[1,] 19 19 24 8
#[2,] 1 6 6 12
# testing
chisq.test(tab1) # p-value = 0.0006819
chisq.test(tab2) # p-value = 0.8818