I was trying to graph an experimental data with a normal curve (for comparisons). I could graph one of the curves just fine, but the normal curve couldn’t be plotted in properly, I could only see a line running down the screen. I get same result for dcauchy. The only curve which is plotted properly is the “pdf_cauchy” variable.
This is what I am trying to do:
plot(pdf_cauchy, type = "l", col = "red", lwd = 4)
curve(dnorm(x, 0, 1), add = T, col = "blue", lwd = 4)
x <- seq(-5, 5, by = .001)
lines(dcauchy(x, 0, 1, FALSE), type = "l", col = "green", lwd = 4)
Here is the data in “pdf_cauchy”
c(0.00127277, 0.00132412, 0.0013786, 0.00143646, 0.00149797,
0.00156345, 0.00163324, 0.00170772, 0.00178731, 0.00187247, 0.00196372,
0.00206165, 0.00216691, 0.00228022, 0.00240241, 0.00253439, 0.0026772,
0.00283202, 0.00300018, 0.00318319, 0.00338278, 0.0036009, 0.0038398,
0.00410205, 0.00439061, 0.00470887, 0.00506072, 0.00545067, 0.00588391,
0.00636639, 0.00690497, 0.00750753, 0.00818301, 0.00894155, 0.00979444,
0.010754, 0.0118334, 0.0130459, 0.0144036, 0.015916, 0.0175867,
0.0194097, 0.0213637, 0.0234058, 0.0254655, 0.0274413, 0.0292036,
0.0306076, 0.0315168, 0.0318319, 0.0315168, 0.0306076, 0.0292036,
0.0274413, 0.0254655, 0.0234058, 0.0213637, 0.0194097, 0.0175867,
0.015916, 0.0144036, 0.0130459, 0.0118334, 0.010754, 0.00979444,
0.00894155, 0.00818301, 0.00750753, 0.00690497, 0.00636639, 0.00588391,
0.00545067, 0.00506072, 0.00470887, 0.00439061, 0.00410205, 0.0038398,
0.0036009, 0.00338278, 0.00318319, 0.00300018, 0.00283202, 0.0026772,
0.00253439, 0.00240241, 0.00228022, 0.00216691, 0.00206165, 0.00196372,
0.00187247, 0.00178731, 0.00170772, 0.00163324, 0.00156345, 0.00149797,
0.00143646, 0.0013786, 0.00132412, 0.0012
Consider what your x-axis is in these graphs. Your initial plot has no x-axis given and therefore just uses 1:100 for the 100 Cauchy values. Now you add a normal curve to that starting at 0 and going to 100 with a mean of 0. You’re only going to get the right half of the curve and and extreme value at that. With a mean of 50 and an sd of 25 you’ll get something more reasonable and you could also do something similar with dcauchy.
You probably really need to put some x-values in your initial plot but I don’t know what they’d be. Did you want the placement to have the peak at 0?… some other value? Only you know what the location and extent of the x-axis should be.