R parallel coordinate plot with fixed scale on X-axis, no matter how large the plot becomes

前端 未结 1 858
执笔经年
执笔经年 2021-01-26 09:13

I am trying to build a parallel coordinate diagram in R for showing the difference in ranking in different age groups. And I want to have a fixed scale on the Y

1条回答
  •  情话喂你
    2021-01-26 10:12

    You can set the panel height to an absolute size based on the number of axis breaks. Note that the device won't scale automatically, so you'll have to adjust it manually for your plot to fit well.

    library(ggplot2)
    library(gtable)
    
    p <- ggplot(Loblolly, aes(height, factor(age))) +
      geom_point()
    
    gb <- ggplot_build(p)
    gt <- ggplot_gtable(gb)
    n <- length(gb$panel$ranges[[1]]$y.major_source)
    
    # locate the panel in the gtable layout
    panel <- gt$layout$t[grepl("panel", gt$layout$name)]
    # assign new height to the panels, based on the number of breaks
    gt$heights[panel] <- list(unit(n*25,"pt"))
    grid.newpage()
    grid.draw(gt)
    

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