stat_contour not able to generate contour lines

后端 未结 3 1367
清酒与你
清酒与你 2020-12-01 12:54

I need to add lines via stat_contour() to my ggplot/ggplot2-plot. Unfortunately, I can not give you the real data from which point val

3条回答
  •  我在风中等你
    2020-12-01 13:24

    Use stat_density2d instead of stat_contour with irregularly spaced data.

    library(ggplot2)
    
    testPts <- data.frame(x=rep(seq(7.08, 7.14, by=0.005), 200))
    testPts$y <- runif(length(testPts$x), 50.93, 50.96)
    testPts$z <- sin(testPts$y * 500)
    
    (ggplot(data=testPts, aes(x=x, y=y, z=z))
    + geom_point(aes(colour=z))
    + stat_density2d()
    )
    

    enter image description here

提交回复
热议问题