How to annotate a reference line at the same angle as the reference line itself?

前端 未结 4 344
情歌与酒
情歌与酒 2020-12-03 05:24

I need to find a way to annotate a reference line at the same angle as the reference line itself.

The following statement will produce the reference line and the la

4条回答
  •  暖寄归人
    2020-12-03 06:06

    Working example for ggplot2:

    slope<-1.3
    asp<-1
    p <- ggplot()
    p<-p+scale_x_continuous(limits = c(1, 15), expand = c(0, 0)) 
    p<-p+scale_y_continuous(limits = c(-8, 20), expand = c(0, 0)) 
    p<-p+geom_abline(intercept = 0, slope = slope)
    p<-p+coord_fixed(asp)
    p<-p+annotate("text", label = "reference line label", x = 3.5, y = 5,  colour = "red",angle=atan(slope*asp)*180/pi)
    p
    

    text with angle:

提交回复
热议问题