ggplot2
(理想的には標準プロットの場合)を使用して、バープロット上に順序付け因子の値を表示したいとします。R - ggplot2で軸上に順序付けられた因子の値を表示する方法
私はこの1つのように命じた要因があります: "どのように練習に満足している:"
を - 絶対にない満足=>値1 - ない満足=>値2 - 満足= >値3 - 私は平均値と値「絶対に満足していない」とbarplotをプロットしたい非常に満足=>値4
- >「非常に満足」軸上の代わりに1 - > 4
ggplot2
でそれを行うことはできますか?私の視点では、主な難しさは、値の分布ではなく、因子の平均をプロットすることです(実際には、私のプロットは順序付けられた因子を整数に変換して作成されます)。
これは私のデータセットのdputの結果です。
structure(c(3L, 2L, 3L, 2L, 2L, 3L, 2L, NA, 2L, 3L, 4L, 2L, 1L
), .Label = c("pas du tout satisfait", "plutôt pas satisfait",
"plutôt satisfait", "très satisfait"), class = c("ordered",
"factor"))
そしてここbarplotの一例である(軸上の値なし...):
コードは以下の通りです。
Toto <- structure(c(3L, 2L, 3L, 2L, 2L, 3L, 2L, NA, 2L, 3L, 4L, 2L, 1L
), .Label = c("pas du tout satisfait", "plutôt pas satisfait",
"plutôt satisfait", "très satisfait"), class = c("ordered","factor"))
TotoNumeric <- as.data.frame(as.integer(Toto))
DataForGggplot2 <- as.data.frame(round(sapply(X = TotoNumeric, FUN = "mean", na.rm = TRUE), 1))
colnames(DataForGggplot2) <- "Donnees"
DataForGggplot2$Etiquette <- "the exercises"
Graphe <- ggplot(data = DataForGggplot2, aes(x = Etiquette, y = Donnees)) +
geom_bar(stat = "identity", fill = "blue") +
scale_y_continuous(limits = c(0, 4))
coord_flip()
print(Graphe)
ご要望が明確でない場合は、詳細をお知らせください。
おかげ
私の例のx軸(質問のラベルではなく、値を持つ軸)。 – Kumpelka
代わりに 'scale_y_continuous(limits = c(0、4)、labels = c(" "、levels(Toto)))を使ってみてください' – Nate
ありがとうございました!最後にシンプル... – Kumpelka