r - 有没有办法在我的图表上放置一条带有标签的垂直线?
问题描述
我试图在我的图表上的特定点放置垂直线。我正在使用ggplot2。我在互联网上环顾四周,没有任何效果。
气候变化新闻指标(标准化和非季节性)
# collect data into dataframes for autoplot
News = cbind(CHNEG ,Google , WSJ )
NewsG_WSJ = cbind(Google ,WSJ )
NewsG_CHNEG = cbind(Google ,CHNEG )
NewsCHNEG_WSJ = cbind(CHNEG ,WSJ )
NewsAll = cbind(Google , WSJ ,CHNEG )
# plot
autoplot(News) #plot data series in individual panels
autoplot(News , facets = FALSE) #plot together
autoplot(NewsCHNEG_WSJ , facets = FALSE) #plot together
autoplot(NewsG_WSJ , facets = FALSE) #plot together
autoplot(NewsG_CHNEG , facets = FALSE) #plot together
数据采用时间序列,日期格式为 200806、200807 等。如果您需要更多信息来提供答案,请礼貌地向我询问更多信息。:) 谢谢!
解决方案
您可以使用geom_vline()
添加垂直线和geom_text()
为线添加标签。例如,
geom_vline(xintercept=(location), colour="grey") +
#before line
geom_text(aes(x=(location), label="\n (text here)", y=(location)),
colour="steelblue", angle=90, text=element_text(size=10)) +
#after line
geom_text(aes(x=(location), label="(text here)\n", y=(location)),
colour="darkred", angle=90, text=element_text(size=10))
推荐阅读
- python - 使用 GeoPandas 创建头部图,调整后的图像很小 - 如何更改比例?
- c# - 如何配置 routeConfig.cs 在根域之后直接接受输入
- vba - 如何获取特定字体颜色内的字符串(向文本添加内容,而不是更改颜色) Find.Text 为空
- apache-kafka - Kafka 未重新启动 - 已清除日志、磁盘空间。重新启动但它一次又一次地关闭
- python - 如何在python的两个列表中获得相同的布尔值
- python - 每当我运行此代码时,它都会向我显示 requests.exceptions.ConnectionError: HTTPSConnectionPool 错误
- python - 使用 QtQuick.Controls 中的任何内容都会引发受保护的模块错误
- angular - IdentityServer4 - Angular 如何将默认登录页面更改为 Angular 组件
- python-3.x - 安装 Kivy 模块时出错
- javascript - 在不同的函数中重复变量声明