我正在嘗試使用連續變數tm_aerobic_vario創建一個小提琴圖,該變數具有以下值:
NA 50 614 30 60 180 120 240 12 60 135 120 25 120 120 60 10 120 90 90 30 0 180 120 30 5 0 0 60 180 120 24 30 30 40 40 0 180 60 180 45 0 10 30 120 120 1 45 15 30 180
代碼是:
ggplot(initdata, aes(x = 1, y = tm_aerobic_vario)) geom_violin(trim=FALSE,fill="gray") geom_boxplot(width=0.1) theme_apa()
它一直堅持它需要一個 x 值(在另一個資料集中,我使用 x 作為“組”,它制作了一個很好的圖表,在 x 軸上有兩個組),盡管我沒有提供 x 值。因此下圖

我可以做什么來替換 X 軸,或者在只有 1 個變數的情況下提供哪個值是正確的?
uj5u.com熱心網友回復:
正如 neilfws 所寫,x 是一個因子,因此您可以通過寫將其留空 x = ""
所以
ggplot(initdata, aes(x = "", y = tm_aerobic_vario)) geom_violin(trim=FALSE,fill="gray") geom_boxplot(width=0.1) theme_apa()
uj5u.com熱心網友回復:
我將其添加為下面的完整示例。如果您想完全擺脫它,您可以進一步編輯軸。
library(ggplot2)
initdata <- data.frame(tm_aerobic_vario = c(NA, 50, 614, 30, 60, 180, 120, 240, 12, 60, 135, 120, 25, 120, 120, 60, 10, 120, 90, 90, 30, 0, 180, 120, 30, 5, 0, 0, 60, 180, 120, 24, 30, 30, 40, 40, 0, 180, 60, 180, 45, 0, 10, 30, 120, 120, 1, 45, 15, 30, 180))
ggplot(initdata, aes(x = "tm aerobic vario", y=tm_aerobic_vario))
labs(x="", y="")
geom_violin(trim = F, fill = "gray")
geom_boxplot(width=0.1)
theme_classic()
# theme(axis.text = element_blank(), axis.ticks.x = element_blank()) # to get rid of axis completely

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/347568.html
