我有以下代碼:
library(tidyverse)
exp<-data.frame(a=c(10,30,80,100),b=c("A","B","C","D"))
exp %>%
ggplot(aes(b,a))
geom_rect(aes(xmin="A",xmax="D",ymin=0,ymax=50,fill="red"))
geom_point()

如您所見,“A”和“D”的值位于 geom_rect() 提供的矩形的邊界上。如何讓 geom_rect() 從 x=0 開始并使用繪圖的整個寬度?我想在我的資料集中使用誤差線,它們以這種方式位于矩形的一半之外。
uj5u.com熱心網友回復:
只需分別設定xmin和xmax到-Inf和Inf。
exp %>%
ggplot(aes(b,a))
geom_rect(aes(xmin=-Inf,xmax=Inf,ymin=0,ymax=50,fill="red"))
geom_point()

uj5u.com熱心網友回復:
我必須修改你exp$a的才能開始0
exp<-data.frame(a=c(0,30,80,100),b=c("A","B","C","D"))
exp %>% ggplot(aes(b,a))
geom_rect(aes(xmin="A",xmax="D",ymin=0,ymax=100,fill="red"))
geom_point()
scale_x_discrete(labels=c("A", "B", "C", "D"), expand=c(0, 0))
scale_y_continuous(expand = c(0, 50))

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380650.html
上一篇:我哪里做錯了
