Can't set limits with coord_trans

后端 未结 2 830
一生所求
一生所求 2021-01-11 20:21

I have some data that show a geometric relationship, but have outliers. For example:

x = seq(0.1, 1, 0.01)
dat = data.frame(x=x, y=10^x)
dat[50:60, 2] = 10

         


        
2条回答
  •  死守一世寂寞
    2021-01-11 20:54

    This may be a slightly simpler work-around:

    library(ggplot2)
    
    x = seq(0.1, 1, 0.01)
    dat = data.frame(x=x, y=10^x)
    dat[50:60, 2] = 10
    
    plot_1 = ggplot(dat, aes(x=x, y=y)) +
             geom_line() +
             coord_cartesian(ylim=c(2, 8)) +
             scale_y_log10(breaks=c(2, 4, 6, 8), labels=c("2", "4", "6", "8"))
    
    png("plot_1.png")
    print(plot_1)
    dev.off()
    

    enter image description here

提交回复
热议问题