0

I get an object df not found when attempting this:

df <- data.frame(durationBin = 1:250, effort = 31:280)

ggplot(df, aes(x = durationBin, y = effort, fill = ..count../sum(df$durationBin == x))) + 
stat_bin2d()

What I'm trying to do is have something like a density plot, except instead of density, I would like "the percentage of points in that column." (That is, all the points in the column is 100%, for each column)

Does anyone know how to do this?

AmagicalFishy
  • 1,249
  • 1
  • 12
  • 36
  • Why not calculate it outside ggplot? And your `df` seems to have two columns, of which `duration` is not one. Ggplot works best when all data is contained in one dataframe. You currently have df, but still plot vectors from the environment. – Heroka Feb 08 '16 at 20:14
  • @Heroka Whoops! I meant ``durationBin``. The reason I don't calculate it outside of ggplot is because it will be different for each column. – AmagicalFishy Feb 08 '16 at 20:16
  • 1
    What do you mean with 'different for each column'? Can you make your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Heroka Feb 08 '16 at 20:18
  • Oh, I messed the code all up, didn't I? It's better now. – AmagicalFishy Feb 08 '16 at 20:25
  • Still unclear what you mean with 'different for each column', sorry. Do you mean "Percentage of total (data)points that belongs to one unique x-bin?" – Heroka Feb 08 '16 at 20:31
  • @Heroka Something like that—if every x-bin were 100%, and that one x-bin is split into 5 y-bins (thus, ``stat_bin2d``), I want the percentage of total (data)points in that y-bin that belongs to that x-bin. – AmagicalFishy Feb 08 '16 at 20:34
  • I would go for processing outside ggplot, default number of bins is 30 and a package like data.table or dplyr can handle this without too much work for you. – Heroka Feb 08 '16 at 20:46

0 Answers0