I am looking for a way to help better visualize the relationship between a independent continuous variable and a binary response variable.
I am trying to understand how I can add a 2nd y axis to the existing plot I have below. I want to get a sense of the response rate over different numerical ranges visually.
- How can I add in the response percent at any given histogram bin? For example if there were 10 observations in a bin and 2 were the positive class, then this would show a response of 20%.
- Ideally it's possible that this would be dynamic in that I might change the # of bins. For instance, I have 10 here, I might want 20 the next time.
- This would be a connected line-chart with the corresponding percentages from #1 on the right y axis.
Or in other words, I want a line chart of the positive class to be displayed as a line chart with % show in Y axis.
library(mlbench)
library(tidyverse)
data(Sonar) ## from mlbench
library(ggplot2)
ggplot(Sonar, aes(x=V11, fill=Class)) +
geom_histogram(col='black', bins = 10) +
scale_fill_manual(values=c("purple", "green")) +
labs(title = "Count Left Y Axis; 'R' class percent of BIN in Right Y Axis" ,
x = 'Variable Value in this case V33', y ='Count of Observations' )
