2

I want to plot a probability histogram overlay with probability curve and compare them between two group. my code is as following,

ggplot(MDmedianall, aes(x= MD_median, y=..density.., fill =IDH.type )) +
 geom_histogram(alpha = 0.5,binwidth = 0.00010,  position = 'identity') +
 geom_density( stat="density", position="identity", alpha=0.3 ) + 
 scale_fill_discrete(breaks=c("0","1"), labels=c("IDH wild type","IDH mutant type")) + 
 scale_y_continuous(labels = scales :: percent) + 
 ylab("Relative cumulative frequency(%)") + 
 xlab("MD median value")

enter image description here

However, the y axis is not what I want, any reasons for that? BTW, how to change the line style and label them within the color square on the right.

bdemarest
  • 14,397
  • 3
  • 53
  • 56
  • 1
    My suggestion is that you look in for specific solutions to each part of your question: formatting ggplot axes ([here](https://stackoverflow.com/questions/11610377/how-do-i-change-the-formatting-of-numbers-on-an-axis-with-ggplot) and [here](http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/)) . And changing line style in ggplot: [here](http://www.sthda.com/english/wiki/ggplot2-line-types-how-to-change-line-types-of-a-graph-in-r-software). Also, it would be helpful if you could provide a reproducible example with your question. – rafa.pereira Jun 15 '17 at 23:49
  • thanks for your helpful link, I don't know why my geon_density make the scale larger than 1, actually it's 3000 in the max value of y axis, still don't know why – Smilingfish Yuan Jun 16 '17 at 00:33
  • @SmilingfishYuan Keep in mind that, for a density plot, probability is determined by the area under the curve, and not the value on the y-axis. – Robert Jun 16 '17 at 01:29

0 Answers0