ggplot2 2.1.0 broke my code? Secondary transformed axis now appears incorrectly

前端 未结 3 532
情歌与酒
情歌与酒 2020-12-17 02:29

Some time ago, I inquired about adding a secondary transformed x-axis in ggplot, and Nate Pope provided the excellent solution described at ggplot2: Adding secondary transfo

3条回答
  •  没有蜡笔的小新
    2020-12-17 02:58

    As suggested above, you can use sec_axis or dup_axis.

    library(ggplot2)
    
    LakeLevels <- data.frame(Day = c(1:365), 
                             Elevation = sin(seq(0, 2*pi, 2 * pi/364)) * 10 + 100)
    
    ggplot(data = LakeLevels) + 
      geom_path(aes(x = Elevation, y = Day)) + 
      scale_x_continuous(name = "Elevation (m)", limits = c(75, 125),
                         sec.axis = sec_axis(trans = ~ . * 3.28084, name = "Elevation (ft)"))
    

    ggplot2 version 3.1.1

提交回复
热议问题