Hey Matt (and everyone)
hope the summer is going great!
Here is a kludgy solution. Suppose that your data are located in an
object "gt", which we'll make a 1000 random deviates from a normal
distribution:
gt<- rnorm(1000)
Let's store the output of the histogram in an object wert
wert<- hist(gt)
Notice that we now have a list of the objects used to max the histogram.
Let's store the highest count total in an object high.count
high.count<- max(wert$counts)
Now, lets do the same for a density
trew<- density(gt)
And we can access the highest y-value by,
high.dens<- max(trew$y)
Now, we need to scale the y-values so that they will be appear on the same
scale as the histogram--we are looking for some value of $x$ such that
high.dens*x = high.count
which, algebra tells us
x = high.count/high.dens
So, we can get the appropriate line by,
trew$y<- trew$y*(high.count/high.dens)
and then we can create the plot by executing
hist(gt)
lines(trew)
and voila! the figures
should be on a similar scale.
Hope that helps
Cheers,
Justin
On Fri, 6 Jul 2007, Matt Chingos wrote:
I'm trying to make a plot of y vs. x that also
includes a density plot of
x, but I need to have the units be different from the density plot than
the units for the y axis.
If anyone knows how to do this and can send some example code my way, I
would greatly appreciate it.
Hope you're all having a good summer--
Matt
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l