stat_contour not able to generate contour lines

后端 未结 3 1351
清酒与你
清酒与你 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:07

    You should generate a z for each combination of x and y using expand.grid or outer. For example:

    library(ggplot2)
    testPts <- transform(expand.grid(x=1:10,y=1:5),z=sin(x*y))
    (ggplot(data=testPts, aes(x=x, y=y, z=z))
     + stat_contour()
     + geom_point(aes(colour=z))
    )
    

    enter image description here

提交回复
热议问题