I am trying to combine two distributed graphs using ggplot. but unsucessful.
Asked
Active
Viewed 654 times
1
-
try `facet_wrap( ~ variable, scales = "free_x")`. Also provide a reproducible example [link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – phaser Jun 21 '17 at 19:08
-
ggplot(X,aes(x=rating, fill = cond)) + geom_density(alpha = .3). When trying this I am getting error like Error: Mapping should be created with aes() or aes_() – Harsh Davey Jun 21 '17 at 19:14
1 Answers
1
If you have provided a reproducible example it'd be easier but apart from reproducing distributions the code below desires what you want:
ggplot(NULL, aes(as.numeric(BIN))) +
geom_bar(aes(fill = "0.2"), data = bin1, alpha = 0.5) +
geom_bar(aes(fill = "0.8"), data = bin2, alpha = 0.5)
Which will give us:
Data:
#some fake data
bin1<-rbinom(1000,100,.2)
bin2<-rbinom(1000,100,.8)
bin1 <- data.frame(cbind(bin1,"0.2"))
bin2 <- data.frame(cbind(bin2,"0.8"))
colnames(bin1)[1] <- "BIN"
colnames(bin2)[1] <- "BIN"
bin1[,1] <- as.numeric(bin1[,1])
bin2[,1] <- as.numeric(bin2[,1])
bin <- rbind(bin1,bin2)
bin <-data.frame(bin)