Hi, I’m trying to plot a histogram and overlay it with its corresponding cumulative frequency plot (actually I’d like the inverse cumulative frequency but let’s walk before we run).
I have the source data in the form of a data frame and can plot a histogram very easily:
plotData <- data.frame(day=seq(1,100), obsCount=as.integer(rnorm(100,120,15)))
plot_ly(data = plotData,
type = "histogram",
x = ~obsCount)
I would now like to overlay a cumulative density plot but am having difficulty working out how to generate the appropriate plot. As far as generating the CDF, R’s ecdf function appears appropriate but for the life of me, I can’t get the output of ecdf to play nice with Plotly.
The ecdf function correctly calculates the CDF and can be plotted but I’m sure we’ll all agree that the aesthetics are not up to scratch
ecdfData <- ecdf(plotData$obsCount)
plot.ecdf(ecdfData)
Beyond this step, I’m not sufficiently versed to be able to get my ecdfData to play nice with Plotly as Plotly is expecting a dataframe which ecdfData certainly is not.
Can anyone point me in right direction to achieve the plot combination I am chasing?