Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouped bar chart with ggplot2 and already tabulated data
    primarykey
    data
    text
    <p>I fit a count model to a vector of actual data and would now like to plot the actual and the predicted as a grouped (dodged) bar chart. Since this is a count model, the data are discrete (X=x from 0 to 317). Since I am fitting a model, I only have already-tabulated data for the predicted values.</p> <p>Here is how my original data frame looks:</p> <pre><code> actual predicted 1 3236 3570.4995 2 1968 1137.1202 3 707 641.8186 4 302 414.8763 5 185 285.1854 6 104 203.0502 </code></pre> <p>I transformed the data to be plotted with ggplot2:</p> <pre><code>melted.data &lt;- melt(plot.data) melted.data$realization &lt;- c(rep(0:317, times=2)) colnames(melted.data)=c('origin','count','realization') </code></pre> <p>So that my data frame now looks like this:</p> <pre><code>head(melted.data) origin count realization 1 actual 3236 0 2 actual 1968 1 3 actual 707 2 4 actual 302 3 5 actual 185 4 6 actual 104 5 &gt; tail(melted.data) origin count realization 631 predicted 1.564673e-27 312 632 predicted 1.265509e-27 313 633 predicted 1.023552e-27 314 634 predicted 8.278601e-28 315 635 predicted 6.695866e-28 316 636 predicted 5.415757e-28 317 </code></pre> <p>When I try to graph it (again, I'd like to have the actual and predicted count --which is already tabulated in the data-- by discrete realization), I give this command:</p> <pre><code>ggplot(melted.data, stat="identity", aes(x=realization, fill=origin)) + geom_bar(position="dodge") </code></pre> <p>Yet it seems like the stat parameter is not liked by ggplot2, as I don't get the correct bar height (which would be those of the variable "count").</p> <p>Any ideas?</p> <p>Thanks,</p> <p>Roberto.</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.
 

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