我用ggplot2生成了這個圖,(我手動添加了紅色矩形)

我想以某種方式“標記”x 軸間隔。
例如; 從 1.45e 08。到 1.46e 08 被命名為“低”,1.46e 08。到 1.47e 08 作為“mid”,我只想在 x 軸上顯示這個標簽而不是值。
我有它所屬的標簽/間隔的每個點的串列,如果它有用,那么該范圍的起始點和結束點的間隔。
我在生成圖表時使用了這段代碼
ggplot(erpeaks, aes(x=pos, y=score), position=position_jitter(w=0,h=0))
geom_point(stat = "identity", width=0.5, aes(colour = factor(label)))
theme(plot.title=element_text(hjust=0.5))
我試圖添加這個,但他只適用于確定間隔
coord_cartesian(xlim = c(144018895.5,146957774.5))
還有這個,但這沒有給出結果。
scale_x_discrete(c(144018895.5,146957774.5),labels = c("low"))
謝謝你。
uj5u.com熱心網友回復:
您可以使用cut()函式 infacet_grid()來顯示某些方面的某些 inverval。
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.1
ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species))
geom_point()
facet_grid(~ cut(Sepal.Width, c(-Inf, 2.75, 3.75, Inf)),
scales = "free_x", space = "free_x")

如果您想分配不同的標簽,您可以事先重新標記剪切。
df <- iris
df$facet <- cut(df$Sepal.Width, c(-Inf, 2.75, 3.75, Inf))
levels(df$facet) <- c("low", "medium", "high")
ggplot(df, aes(Sepal.Width, Sepal.Length, colour = Species))
geom_point()
facet_grid(~ facet,
scales = "free_x", space = "free_x")

由reprex 包(v2.0.1)于 2021 年 11 月 30 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371950.html
上一篇:RggplotdateTime資料并使用年份作為分組變數
下一篇:將geom_map與transition_time一起使用會得到錯誤:insert_points(polygon$x,polygon$y,splits,n)中的錯誤
