0

I have this r code in ggplot to do a plot

ggplot(ab,aes(x=pk1)) + geom_histogram(binwidth = 0.5, position= 
position_dodge(0.5), color="black",fill="cadetblue4")+ ggtitle("Histogram of
PK1")+labs( x="PK1", y="Number of
Observations")+geom_density(aes(y=0.5*..count..))+
scale_x_continuous(breaks=seq(0,10,0.5))

I want to have a separate y-axis on the right side with the actual values of the PDF rather than doing aes(y=0.5*..count..) to the original plot to make the curve fit. I want both the histogram and density curve on the same plot.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Ar De
  • 105
  • 1
  • 1
  • 3
  • 2
    Try looking at the posts here! http://stackoverflow.com/questions/3099219/plot-with-2-y-axes-one-y-axis-on-the-left-and-another-y-axis-on-the-right – sconfluentus Apr 14 '17 at 00:43
  • Yes, but that is still 2 separate plots. I need both on the same plot. – Ar De Apr 14 '17 at 02:24
  • 1
    look at the one with 31 comments, it shows you how to add a second axis to your plot...and the one by Alessandro Jacopson shows you how to place two plots. – sconfluentus Apr 14 '17 at 02:58
  • ...as does the one by tstenner. There's a lot of good answers there. If you can't get them working, edit your question to show your attempts and we'll help you debug. – Gregor Thomas Oct 12 '17 at 15:08

0 Answers0