Extract data from a ggplot

前端 未结 3 1193
猫巷女王i
猫巷女王i 2020-11-27 03:49

I have made a plot using ggplot2 geom_histogram from a data frame. See sample below and link to the ggplot histogram Need to label each geom_vline

3条回答
  •  隐瞒了意图╮
    2020-11-27 04:26

    If you need just data it seems layer_data is designed precisely for this :

    layer_data(p, 1)
    

    It will give you the data of the first layer, same as ggplot_build(p)$data[[1]].

    Its source code is indeed precisely function (plot, i = 1L) ggplot_build(plot)$data[[i]]

提交回复
热议问题