这看起来很简单,但有一些基本的东西我没有理解。我有一个数据框,其中每月的一些事件计数为列,每年的事件计数为行。像这样:
season sep oct nov dec jan feb
2000 2 7 47 152 259 140
2001 1 5 88 236 251 145
2002 2 14 72 263 331 147
2003 5 6 71 207 290 242
Run Code Online (Sandbox Code Playgroud)
首先,我想创建一个季节的条形图。例如,对于 2000 年赛季,条形图将每个月的值显示为垂直条(唉,没有足够的代表点来发布示例图像)。我猜我需要以某种方式重塑我的数据?
最终,我想创建一组多方面包裹的图表,每个季节一个。
请注意,我发现了一篇类似的帖子,但由于问题不够清晰,该帖子过于复杂。
library(reshape2)
library(ggplot2)
df_m <- melt(df, id.vars = "season")
Run Code Online (Sandbox Code Playgroud)
为了策划一季(例如2000年)
ggplot(subset(df_m, season == "2001"), aes(x = variable, y = value)) +
geom_bar(stat = "identity")
Run Code Online (Sandbox Code Playgroud)
对于分面包裹的图表集,请尝试:
ggplot(df_m, aes(x = variable, y = value)) + geom_bar(stat = "identity") +
facet_wrap(~season)
Run Code Online (Sandbox Code Playgroud)
