【发布时间】:2015-01-24 05:51:44
【问题描述】:
我想添加一个彩色箭头(轴的全长)以显示沿某个方向移动 a 的时间(可以假设,但是对于此图没有数值,因此我希望箭头显示方向)。我可以使用geom_segment 来绘制它,但是绘图区域之外的部分丢失了。
我看过这篇文章:R & ggplot2: How to get arrows under the axis label? 但这个解决方案是对轴标题的破解。这篇文章:https://stackoverflow.com/a/10542622/1000343 显示文本区域之外的行,但不显示彩色箭头。
MWE
library(ggplot2); library(grid); library(scales)
dat <- data.frame(Time=0:5, y=0:5)
ggplot(dat, aes(x=Time, y=y)) +
geom_area(alpha=.1) + theme_bw() +
scale_y_continuous(expand = c(0, 0)) +
scale_x_continuous(expand = c(0, 0)) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()
)
我试过了:
ggplot(dat, aes(x=Time, y=y)) +
geom_area(alpha=.1) + theme_bw() +
scale_y_continuous(expand = c(0, 0)) +
scale_x_continuous(expand = c(0, 0)) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()
) +
geom_segment(aes(x=0, xend = 5 , y=0, yend = 0), size=1.5,
arrow = arrow(length = unit(0.6,"cm")))
给予
但我想要
【问题讨论】: