带格子的堆叠条形图:我的数据太大了吗?

发布于 2024-09-10 16:46:12 字数 1258 浏览 3 评论 0原文

我想要一个看起来类似于 格子中给出的示例的图表文档

#EXAMPLE GRAPH, not my data
> barchart(yield ~ variety | site, data = barley,
+          groups = year, layout = c(1,6), stack = TRUE, 
+          auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
+          ylab = "Barley Yield (bushels/acre)",
+          scales = list(x = list(rot = 45))) 

融化我的数据以获得这个“长”形式的数据框:

> str(MDist)
'data.frame':   34560 obs. of  6 variables:
$ fCycle   : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
$ location : Factor w/ 96 levels "c1","c10","c11",..: 1 1 1 1 1 1 1 1 1 1 ...
$ timepoint: num  1 2 3 4 5 6 7 8 9 10 ...
$ variable : Factor w/ 3 levels "inadist","smldist",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value    : num  0 55.7 75.3 99.2 45.9 73.8 79.3 73.5 69.8 67.6 ...

我想为每个组名和fCycle创建一个堆叠条形图。我尝试了这个:

barchart(value~timepoint|groupname*fCycle, data=MDist, groups=variable,stack=T) 

它不会抛出任何错误,但 30 分钟后它仍然在思考。这是因为它不知道如何处理对每个条形有贡献的 36 个值吗?如何使条形图更容易消化这些数据?

I want a graph that looks similar to the example given in the lattice docs:

#EXAMPLE GRAPH, not my data
> barchart(yield ~ variety | site, data = barley,
+          groups = year, layout = c(1,6), stack = TRUE, 
+          auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
+          ylab = "Barley Yield (bushels/acre)",
+          scales = list(x = list(rot = 45))) 

I melted my data to obtain this "long" form dataframe:

> str(MDist)
'data.frame':   34560 obs. of  6 variables:
$ fCycle   : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
$ location : Factor w/ 96 levels "c1","c10","c11",..: 1 1 1 1 1 1 1 1 1 1 ...
$ timepoint: num  1 2 3 4 5 6 7 8 9 10 ...
$ variable : Factor w/ 3 levels "inadist","smldist",..: 1 1 1 1 1 1 1 1 1 1 ...
$ value    : num  0 55.7 75.3 99.2 45.9 73.8 79.3 73.5 69.8 67.6 ...

I want to create a stacked barchart for each groupname and fCycle. I tried this:

barchart(value~timepoint|groupname*fCycle, data=MDist, groups=variable,stack=T) 

It doesn't throw any errors, but it's still thinking after 30 minutes. Is this because it doesn't know how to deal with the 36 values that contribute to each bar? How can I make this data easier for barchart to digest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖鼻大婶 2024-09-17 16:46:12

我不太了解格子,但这可能是因为您的 timepoint 变量是数字,而不是因子?

I don't know lattice well, but could it be because your timepoint variable is numeric, not a factor?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文