Rの集計データからヒストグラムを作成するにはどうすればよいですか?要約データからヒストグラムを作成するR
私はこれを試みた:
dataset <- c(4,17,12,6)
hist(dataset)
はしかし、これは私が希望 "0-19"、 "60〜99" ブレイクなどせずにデータ
を示しました。正しい区切りと名前でこのヒストグラムを作成する方法を知っている。ありがとう。
Rの集計データからヒストグラムを作成するにはどうすればよいですか?要約データからヒストグラムを作成するR
私はこれを試みた:
dataset <- c(4,17,12,6)
hist(dataset)
はしかし、これは私が希望 "0-19"、 "60〜99" ブレイクなどせずにデータ
を示しました。正しい区切りと名前でこのヒストグラムを作成する方法を知っている。ありがとう。
が、この中にバーの幅はビンのサイズに比例することになる、これを試してみてください:
# make data. we add a value in the middle of the bin so that later ggplot knows
# what bin to put it into. However, any value within the bin can be selected.
# For instance, rep(x = 1, times = 4) for the first of vals would give the bin
# 0-19, 4 times.
df = data.frame(
vals = c(
rep(x = 10, times = 4),
rep(x = 30, times = 17),
rep(x = 50, times = 12),
rep(x = 80, times = 6)
)
);
# load ggplot2
library(ggplot2);
# make a histogram
ggplot(data = df, mapping = aes(x = vals)) +
# set the breaks to be what you desire.
geom_histogram(breaks = c(0, 19, 20, 39, 40, 59, 60, 99))
これらの4つの数字はすでにRにありますか? 'barplot(c(" 0-19 "= 4、" 20-39 "= 17、" 40-59 "= 12、" 60-99 "= 6))'はあなたをかなり遠くに運ぶでしょう。 R-sの観点からは、ヒストグラムではなく、棒グラフであることに注意してください。 –
[ヒストグラムをプロットするには?](https://stackoverflow.com/questions/38480183/how-to-plot-histogram-in-r) – lebelinoz