This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Plot two graphs on different levels on y axis (primary and secondary) using ggplot

Hi I want to create a plot similar to below, Basically, the data on x axis is continous, and data on primary y axis ia a factor (0,1). On secondary y axis it freq or counts on data points in each bin on x axis

How can I plot something similar to this in ggplot? This is my data frame example:

head(data2)

A tibble: 6 x 4

x_bin Death_prob Val
<fct> <int> <int> 1 (0.668,2.39] 0 49
2 (0.668,2.39] 1 3
3 (2.39,4.11] 0 92
4 (2.39,4.11] 1 8
5 (4.11,5.84] 0 27
6 (4.11,5.84] 1 8

the graph is showing DNA concentration on x axis (in percentage, and it is binned), and probability of death (0=alive, 1=Dead) on primary y axis, and the number of measured data points in each bin is indicated by the blue bar graphs (right Y axis). it is a beautiful graph to show lots of info in one plot. I am able to plot the data on x axis and primary y axis, but I am unable to plot the blue graphs separately for level 0 and 1 on secondary y axis.

Example plot is here:

twoboxplots

ggplot r

0 answers

No answers yet.

Log in to answer this question.