代码之家  ›  专栏  ›  技术社区  ›  vestland

在GGPROT2Y3.3.0中检索轴标签的值

  •  5
  • vestland  · 技术社区  · 6 年前

    20, 30, 40 10 , 15 ,20 ,25, 30, 35

    情节

    r-statistics.co

    enter image description here

    可复制代码

    # Scatterplot
    theme_set(theme_bw())  # pre-set the bw theme.
    g <- ggplot(mpg, aes(cty, hwy))
    g + geom_count(col="tomato3", show.legend=F) +
      labs(subtitle="mpg: city vs highway mileage", 
           y="hwy", 
           x="cty", 
           title="Counts Plot")
    

    我试过查看 str(g)

    2 回复  |  直到 5 年前
        1
  •  5
  •   Chris    6 年前

    基于CPak的回答,该结构在 ggplot2_3.0.0 . 现在可以使用以下命令提取标签:

    ggplot_build(g)$layout$panel_params[[1]]$y.labels
    #[1] "20" "30" "40" 
    ggplot_build(g)$layout$panel_params[[1]]$x.labels
    #[1] "10" "15" "20" "25" "30" "35"
    
        2
  •  1
  •   CPak    6 年前

    在旧邮件上扩展-可以使用

    ggplot_build(g)$layout$panel_ranges[[1]]$y.labels
    # "20" "30" "40"
    ggplot_build(g)$layout$panel_ranges[[1]]$x.labels
    # "10" "15" "20" "25" "30" "35"
    

    ggplot2_2.2.1 但不是 ggplot2 version 3.0.0 -感谢zx8754和nilambara指出这一点