EGM*_*686 0 r ggplot2 tidyverse
通常我会在 Excel 中创建这样的图:
我正在探索将它移动到 ggplot,但是在我没有看到可以使用的几何图形中,关于如何使用 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()
Run Code Online (Sandbox Code Playgroud)
可重复的数据
df <- data.frame(x = c(10,25,65),
label = c("Variable1","Variable2","Variable3"))
Run Code Online (Sandbox Code Playgroud)