Hi:
After looking at Josh's nicely done example at the UCLA site, I made a
couple of changes to your code; in particular, your bandwidth needs to
be reduced because the response ranges from 0 to 1. If you set the
bandwidth to 1, you'll only get one or two histogram bars and it's
pointless to draw a density plot over it.
p <- ggplot(TobitTimeH3, aes(x = PctWeakTies, fill = factor(NR_score)))
p + stat_bin(binwidth = 0.1) +
stat_function(fun = f, size = 1,
args = list(var = TobitTimeH3$PctWeakTies, bw = 0.1))
NR_score was converted to a factor; once that was done, the error
message disappeared. However, I wonder about the purpose of using 12
distinct fill colors in a single histogram. Perhaps some form of
aggregation of scores is in order (see the cut() function).
Dennis