Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your title should be changed to "Dodged Bar Chart" instead of 2D histogram, because histograms have continuous scale on x axis unlike bar chart and they are basically used for comparing the distributions of univariate data or the distributions of univariate data modeled on the dependent factor. You are trying to compare colB vs colC which can be effectively visualized using a 2D scatter plot but not with bar chart. The better way to compare the distributions of colB and colC using histograms would be plotting two histograms separately and check the change in location of the data points.</p> <p>If you want to compare distributions of colB and colC, try the following code: I did round up the values for getting a reasonable data per your data description. Notice a random sampling by permutation is happening and everytime, you run the same code, there will be slight change in the distribution, but that will not affect the inference of distribution between colB and colC.</p> <pre><code>library("ggplot2") # 44 datapoints between 1-10 a &lt;- rep(1:10, 4) a &lt;- c(a, sample(a, size=4, replace=FALSE)) # 25 datapoints between 11-20 b &lt;- rep(11:20, 2) b &lt;- c(b, sample(b, size=5, replace=FALSE)) # 31 datapoints between 21-30 c &lt;- rep(21:30, 3) c &lt;- c(c, sample(c, size=1, replace=FALSE)) colB &lt;- c(a, b, c) # 64 datapoints between 1-10 a &lt;- rep(1:10, 6) a &lt;- c(a, sample(a, size=4, replace=FALSE)) # 36 datapoints between 11-20 b &lt;- rep(11:20, 3) b &lt;- c(b, sample(b, size=6, replace=FALSE)) colC &lt;- c(a, b) df &lt;- data.frame(cbind(colB, colC=colC)) write.table(df, file = "data") data &lt;- read.table("data", header=TRUE) data ggplot(data=data, aes(x=colB, xmin=1, xmax=30)) + stat_bin(binwidth = 1) ggplot(data=data, aes(x=colC, xmin=1, xmax=30)) + stat_bin(binwidth = 1) # if you want density distribution, then you can try something like this: ggplot(data=data, aes(x=colB, y = ..density.., xmin=1, xmax=30)) + stat_bin(binwidth = 1) ggplot(data=data, aes(x=colC, y = ..density.., xmin=1, xmax=30)) + stat_bin(binwidth = 1) </code></pre> <p>HTH -Sathish</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload