1

我正在尝试生成一个包含数千个数据的条形图。

我对 ggplot 有尺寸问题。

代码 :

ggplot(data = df, aes(x=extension, y=duration)) +
  geom_bar(stat="identity", width=10,fill="steelblue")+
  ggtitle("Chart") + 
  xlab("Number") +
  ylab("Duration") +
  theme(legend.position = "none")+
  theme(plot.title = element_text(hjust = 0.5), plot.subtitle = element_text(hjust = 0.5))+ 
  coord_flip()

输出:

图表输出

从 MongoDB 加载数据帧。数据框:

1        36952  7158803
2        36110  7068360
3        36080  4736043
4        36509  4726630
5        36890  4699026
6        36051  4698594
7        36783  4677233
8        36402  4672623
9        36880  4672093
10       36513  4655583
11       36522  4630962
12       36116  4628046
13       36746  4593291
....
4

1 回答 1

0

从您的示例图表中,我推断您的 x 轴 ( extension) 可能是一个因素。如果它是数字,ggplot将正确缩放轴。

我建议检查数据集列的类别。确保两者都是数字。或者,您必须想出适当的 x 轴缩放比例。

这是您翻转的 x 轴是一个因素的图;ggplot尝试渲染因子的每个单独级别,并且它们重叠,因为有很多。我快速创建了一些假数据来模仿你的。

在此处输入图像描述

extension是数字并ggplot正确缩放的图。

在此处输入图像描述

于 2020-07-15T07:11:02.890 回答