stat_contour with data labels on lines

前端 未结 2 1896
悲哀的现实
悲哀的现实 2020-12-14 02:54

I wonder how to get data labels on lines in ggplot2 for contours. Thanks

require(grDevices) # for colours

x <- seq(-4*pi, 4*pi, len = 27)
y          


        
相关标签:
2条回答
  • 2020-12-14 03:14

    This is an old question already answered, but I do a lot of contour plots and I think that there is an easier and more versatile way to do this using the package metR (https://rdrr.io/github/eliocamp/metR/f/vignettes/Visualization-tools.Rmd). This package has the function geom_label_contour() that provides an easy way to plot labels of contours. Also provides a lot of functions to plot maps.

    library(ggplot2)
    library(reshape2)
    library(metR)
    volcano3d <- melt(volcano)
    colnames(volcano3d) <- c('x','y','z')
    
    ggplot(data = volcano3d, aes(x=x,y=y,z=z)) + geom_contour() +
      geom_label_contour()
    
    0 讨论(0)
  • 2020-12-14 03:21

    using directlabels package and picking solution from this

    # Basic plot
    v <- ggplot(volcano3d, aes(x, y, z = z))
    library(directlabels)
    v2 <- v + stat_contour(aes(colour = ..level..))
    direct.label(v2, method="bottom.pieces")
    

    enter image description here

    0 讨论(0)
提交回复
热议问题