如何在两点之间使用geom_hline

时间:2016-08-14 00:02:50

标签: r ggplot2

我正在制作一个Ramachandran情节,我想在两点之间划一条线。我正在使用此代码:

      size      lines name
      156K        708 sash
       16K         64 hostname
      120K        460 netstat
       40K        110 fuser
      644K       1555 dir/bash
       28K         82 keyctl
      2.3M       8067 vim

我有这个:

enter image description here

但是我想把另外两条水平线放在这个图上:

enter image description here

我使用了hline,但不知道如何在两点之间定义它。

1 个答案:

答案 0 :(得分:2)

使用geom_segment

df <- data.frame(x1 = 0, x2 = -180, y1 = 0, y2 = 0) #Data frame with the points

  ggplot(result) + 
  scale_x_continuous(limits = c(-180,180), breaks = seq(-180,180,40), expand=c(0,0)) +
  scale_y_continuous(limits = c(-180,180), breaks = seq(-180,180,40), expand=c(0,0)) +
  geom_hex(aes(x, y), bins = 500) +
  geom_vline(xintercept = 0, colour="red", linetype = "longdash") +
  geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2, colour = "segment"), data = df)+
  scale_fill_gradientn("", colours = rev(rainbow(10, end = 4/6))) + ylab(expression(paste(psi))) + xlab(expression(paste(phi)))