Barplot:绘制值范围

时间:2017-01-11 11:55:08

标签: r plot ggplot2 bar-chart

我想绘制年份中变量值的范围。 我已经使用绘图点完成了它,但是点使查看变得困难。所以我想用吧。有谁知道怎么做?

我在下面放了一个关于我想要的例子的代码,但是使用了绘图点。

Degrees <- c(20, 19, 18, 20, 19, 18, 17, 10, 9,  8)
Year <- c("85", "85", "85", "86", "86", "86", "86", "87", "87", "87")
df <- data.frame (Degrees=Degrees, Year=Year)
p <- ggplot(df, aes(Year, Degrees))
p + geom_point()

3 个答案:

答案 0 :(得分:2)

或许是这样的?

var someValue = new int?(42) ?? 8; // Produces ldc.i4.8

enter image description here

答案 1 :(得分:1)

以编程方式查找每年的最小值和最大值,并为列指定专有名称:

year_min <- setNames(aggregate(df$Degrees, by = list(df$Year), min), c("Year", "Degrees"))
year_max <- setNames(aggregate(df$Degrees, by = list(df$Year), max), c("Year", "Degrees"))

将它们连接成数据帧:

df_merge <- rbind(year_min, year_max)

然后做一个方框图

boxplot(Degrees~Year, data=df_merge)

Boxplot with min and max values per year only

答案 2 :(得分:0)

我想你可能想要一个箱形图,即描绘某一年的价值范围,而不是一个条形图......

p <- ggplot(df, aes(Year, Degrees))
p + geom_boxplot()

enter image description here

条形图看起来像这样(价值按年份汇总):

p <- ggplot(df, aes(Year, Degrees))
p + geom_bar(stat="identity")

enter image description here

相关问题