Tuesday 15 March 2011

r - Error with ggplot2 mapping variable to y and using stat="bin" -


I am using ggplot2 to create a histogram:

  geom_histogram (AES X = ..), y = "..ncount ../ sum (..ncount ..)")   

and I get an error:

 < Maping a variable for code> Y and using stat = "bin" With stat = "bin", it will try to set the value of y to count the cases in each group. This can lead to unexpected behavior and will not be allowed in future versions of ggplot2. If you want to represent Y counting of cases, use stat = "bin" and do not map a variable for y. If you want to display values ​​in Y data, use stat = "identity" for example? View Geom_bar? (Dissolved; last used in Version 0.9.2)   

What is the common reason for this? I'm confused about this error because I'm not doing a variable mapping for y , just histogram-ing x and the height of the histogram strip is the normalized fraction Would like to represent the data (such as collecting all the time heights are 100% of the data part.)

Edit : If I make a plot of density I want geom_histogram E>, do I use ..ncount ../ sum (..ncount ..) or .. scaled .. ? ? I am not clear about the .. scaled .. .

Confusion is a long time ) That all begin with stat_bin .

But users generally do not know that their illusion revolves around Stat_bin , since they usually have geom_bar or When facing problems using geom_histogram . Note the documents for each: They use both stat = "bin" by default .

But we back it up geom _ * controls the actual rendering of data in any type of geometric form stat_ * just your data It changes. In practice, it is a bit misleading, because by adding a layer of stat_bin , by default, call geom_bar and therefore it may seem indistinguishable from geom_bar .

In any case, consider the land like "bar", histogram and bar chart. Both are clearly going to include some binning of data somewhere along the line, but our data can either be pre-summarized or not, for example, once we can take the plot from here: < Pre> xaaabbb

or equivalent

  xya 3b3   

not done yet The second pre-bidin is the default behavior for both geom_bar and geom_histogram assumes that you have not your day Security has been pre-Bain so they will default to stat_bin try to call your x values.

According to the warning, it will then attempt to map to y for the resulting numbers for you, if you also to y Try to change the map to any other variable, so you have a dragons area here. For the functions of the variable returned by stat_bin ( .. count .. .. , etc.), the mapping y should be corrected and that warning Do not throw (this does not use the example of ME for me).

The move here is that if you pre-calculated the heights of the bars for geom_bar , then always stat = "identity" Remember to use geom_histogram is not very likely that you will pre-compute the box, so in most cases you y to y to <> stat_bin .

geom_dotplot uses its own Binny State, stat_bindot , and this discussion also applies here, I believe. This type of thing is generally not a problem with cases of 2d Binings ( geom_bin2d and geom_hex ), because there is not much flexibility available in the form of analogy Show the Z variable in the 1D case y in the variable. If future updates allow for more fancy joints of 2D Binning cases, then I think that you have to see something there.

No comments:

Post a Comment