r - 用 R + ggplot 在折线图中画一个点
解决方案
您可以执行以下操作:
library(ggplot2)
ggplot(df, aes(x = x, y = 1, label= label))+
scale_x_continuous(limits = c(0,100))+
geom_segment(x = 0, xend = 100, y = 1, yend = 1, color = "blue")+
geom_segment(x = 0, xend = 0, y = 0.99, yend = 1.01, color = "blue")+
geom_segment(x = 100, xend = 100, y = 0.99, yend = 1.01, color = "blue")+
geom_point(color = "red", size = 3)+
geom_segment(aes(x = x, xend = x, y = 0.99, yend = 1.01),color = "red")+
ylim(0.9,1.1)+
geom_text(aes(y = 1.025))+
geom_text(aes(y = 0.975, label = paste(x,"%", sep = "")))+
annotate(geom= "text",label = 0, y = 0.975, x = 0)+
annotate(geom = "text", label = 100, y = 0.975, x = 100)+
theme_void()
可重现的数据
df <- data.frame(x = c(10,25,65),
label = c("Variable1","Variable2","Variable3"))
推荐阅读
- c++ - 即使包含正确的标题,g ++说函数也不存在
- akka-http - 如何通过akka http实现透明代理
- angular - rxjs+angular:在 Web 服务调用出错后“杀死”可观察对象
- c# - 检索自定义 VSTO 插件的数据
- android - 找不到任何与 com.google.android.gms:strict-version-matcher-plugin:[15.0.0, 16.0.0) 匹配的版本
- kubernetes - 使用 kubeadm 为什么要手动生成证书?
- python - Pandas 过滤一个系列
- django - Django 动态选择字段,约会位置
- tensorflow - 修复当前 Google Colab TF 版本中没有模块“层”
- windows - 如何自动更新使用 Inno Setup 安装的应用程序