我需要一些幫助。
我正在使用,ggridges但我最終遇到了下面舉例說明的問題:
我得到了一個錯誤的順序,即 y 軸的 (1, 10, 11, 2)。我希望最后一個數字的 y 軸順序為 (1, 2, 3, 10, 20) 代碼如下:
library(ggplot2)
library(ggridges)
iris1 <- iris
iris2 <- iris
# change levels
levels(iris1$Species) <- c(1,2,10)
levels(iris2$Species) <- c(1, 3, 20)
# offset iris2 so we can see it
iris2$Sepal.Length <- iris2$Sepal.Length 1
# PLots with correct order of y
ggplot() geom_density_ridges(data = iris1, aes(x = Sepal.Length, y = Species))

# the addition of layers throws off the order
ggplot()
geom_density_ridges(data = iris1, aes(x = Sepal.Length, y = Species))
geom_density_ridges(data = iris2, aes(x = Sepal.Length, y = Species))

uj5u.com熱心網友回復:
根據您想要的結果,第二個選項是通過以下limits引數設定順序scale_y_discrete:
library(ggplot2)
library(ggridges)
ggplot()
geom_density_ridges(data = iris1, aes(x = Sepal.Length, y = Species))
geom_density_ridges(data = iris2, aes(x = Sepal.Length, y = Species))
scale_y_discrete(limits = as.character(c(1, 2, 3, 10, 20)))

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/407013.html
標籤:
