Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在两点之间使用geom_hline_R_Ggplot2 - Fatal编程技术网

R 如何在两点之间使用geom_hline

R 如何在两点之间使用geom_hline,r,ggplot2,R,Ggplot2,我正在画一个拉玛钱德兰的情节,我想在两点之间画一条线。我正在使用以下代码: 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

我正在画一个拉玛钱德兰的情节,我想在两点之间画一条线。我正在使用以下代码:

 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") +
  scale_fill_gradientn("", colours = rev(rainbow(10, end = 4/6))) + ylab(expression(paste(psi))) + xlab(expression(paste(phi)))
我有这个:

但我想再画两条水平线,如下图所示:


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

使用
geom\u段

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)))

df在基本图形或晶格图形中,两点之间的“线”称为“段”。似乎确实存在geom_段gglot2函数。162次点击搜索
[r]ggplot2段
@42-是!。谢谢,我找到了答案。