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-是!。谢谢,我找到了答案。