私は子供の性的虐待研究に取り組んでいます。このために、lattice
を使用してクラスター化された棒グラフを作成したいと考えています。私は次のコードを使用しました。lattice:Clustered Barchart:棒グラフをソートして棒の上に値を表示
マイデータ:
nature <- read.table(text = "Nature_of_sexual_abuse, Familiarity_with_the_perpetrator, Count
Talked in a sexual way, Not familiar at all, 21
Talked in a sexual way, Not very familiar, 22
Talked in a sexual way, Very familiar, 22
Shown pornography, Not familiar at all, 6
Shown pornography, Not very familiar, 17
Shown pornography, Very familiar, 16
Looked at private parts, Not familiar at all, 16
Looked at private parts, Not very familiar, 14
Looked at private parts, Very familiar, 10
Touched private parts, Not familiar at all, 6
Touched private parts, Not very familiar, 15
Touched private parts, Very familiar, 11
Made a sex video, Not familiar at all, 1
Made a sex video, Not very familiar, 6
Made a sex video, Very familiar, 7
Forced sex behaviors, Not familiar at all, 5
Forced sex behaviors, Not very familiar, 17
Forced sex behaviors, Very familiar, 10",
header = TRUE,
sep = ",", strip.white = TRUE)
私のプロット:
library(lattice)
colors = c("lightsalmon3", "lightgoldenrod2", "cadetblue4")
barchart(
data = nature,
origin = 0,
Count ~ Nature_of_sexual_abuse,
groups = Familiarity_with_the_perpetrator,
xlab = list (
label = "Nature of sexual abuse",
font = 2,
cex = 1),
ylab= list (
label = "Number of students",
font = 2,
cex = 1),
ylim=c(0,25),
labels = TRUE,
auto.key = list(space="top", columns= 3),
par.settings = list(superpose.polygon = list(col = colors)))
チャートは現在、次のようになります。
しかし、私はそれは次のようにソートしたいですNature_of_sexual_abuse
の変数:「メイドのセックスビデオ」、「強制的なセックス」 「秘密の部分を見る」、「触れられた秘密の部分」、「ポルノに描かれた」、「性的な方法で話された」などがあります。
各クラスタ内で、グラフはFamiliarity_with_the_perpetrator
の変数でソートされていなければなりません。「非常によく知られています」、「あまりよく知られていません。
私はそれを表示したい順番でデータを送ろうとしました。しかし、lattice
は自動的にグループをアルファベット順にソートしているようです。
私はまた、各バーの値がバーの一番上に表示されるようにします。誰かが私が望む順序でそれをグループ化するのを助けてくれますか?あなたが見ることができるように
、私はR.そうに初心者です、任意のヘルプは、多くのことを理解されるであろう。
、あなたは[コメントで]リンクで与えられた解決策を試してみました(https://stackoverflow.com/questions/45222720/r-lattice-how-to-remove-white-space-between-バーとx軸#comment77414934_45222720)を入力してください。あなたがして、それが仕事をしなかった場合は、あなたの質問にこれを表示してください、そしてなぜそれが動作しなかったかを示してもらえますか? – user20650