Histogramms are commonly used in data analysis to observe distribution of variables.
Really often we need to compare the distribution of 2 variables simultaneously.
There is a tip to present the 2 distribution together (using the add function) with transparency (using the rgb function) to keep information when data override.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#Create data Ixos=rnorm(4000 , 100 , 30) Primadur=rnorm(4000 , 200 , 30) #Represent separately first par(mfrow=c(1,2)) hist(Ixos, breaks=30 , xlim=c(0,300) , col=rgb(1,0,0,0.5) , xlab="height" , ylab="nbr of plants" , main="" ) hist(Primadur, breaks=30 , xlim=c(0,300) , col=rgb(0,0,1,0.5) , xlab="height" , ylab="nbr of plants" , main="") #But it is hard to visualize differences in the distribution. #It would be more interesting to have both distribution on the same graph, #with transparency permitting to see the whole distribution : hist(Ixos, breaks=30, xlim=c(0,300), col=rgb(1,0,0,0.5), xlab="height", ylab="nbr of plants", main="distribution of height of 2 durum wheat varieties" ) hist(Primadur, breaks=30, xlim=c(0,300), col=rgb(0,0,1,0.5), add=T) legend("topright", legend=c("Ixos","Primadur"), col=c(rgb(1,0,0,0.5), rgb(0,0,1,0.5)), pt.cex=2, pch=15 ) |
Not really what you are looking for ? Make a new search !
Leave a Reply