我可以在嵌入饼图的 R 条形图中制作这样的图表吗

发布于 2024-12-25 13:22:05 字数 513 浏览 3 评论 0原文

我有以下数据:

    I   II  Total 
A   15  25  40
B   5   45  50
C   15  5   20

R 数据输入:

group <- c("A", "B", "C", "A", "B", "C")
subgroup <- c("I", "I", "I", "II", "II", "II")
yvar <- c(15, 5, 15, 25, 45, 5)

当我在考虑更好的方式来呈现它时,我想到了饼图(最好是 3D)与条形图(最好是 3D)相结合的想法。这是我的想法的粗略草图,其中将条形图嵌入到饼图中。如果您有任何其他创新想法来呈现此类数据,请建议我。

在此处输入图像描述 在此处输入图像描述

I have following data:

    I   II  Total 
A   15  25  40
B   5   45  50
C   15  5   20

R data input:

group <- c("A", "B", "C", "A", "B", "C")
subgroup <- c("I", "I", "I", "II", "II", "II")
yvar <- c(15, 5, 15, 25, 45, 5)

As I was thinking a better way to present it, I came to idea of pie chart (preferably 3D) combined with bar chart (preferably 3D). Here is my rough sketch of my idea where bar chart is embedded into pie chart. Please suggest me if you have any other innovative idea to present such data.

enter image description here
enter image description here

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

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

发布评论

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

评论(5

〃温暖了心ぐ 2025-01-01 13:22:05

我极力推荐您阅读 Edward Tufte 的一些关于图表和定量数据显示的文献。饼图几乎是向用户传递信息的最糟糕的方式。在图表中使用“3-D”图像(例如条形图)充其量被认为是幼稚的——它对提高可读性或信息流没有任何作用。

那么让我问:您想向读者提供什么信息(以及什么结论)?您为什么要两次呈现相同的信息?

I cannot recommend strongly enough that you read some of Edward Tufte's literature on graphs and the display of quantitative data. Pie charts are close to the worst possible way to impart information to the user. Use of "3-D" images (e.g. bars) in charts is considered puerile at best -- it does nothing to improved readability or information flow.

So let me ask: what information (and what conclusions) are you trying to give to your reader? Why would you want to present the same information twice?

谁把谁当真 2025-01-01 13:22:05

如果您有任何其他创新想法来呈现此类数据,请建议我

我没有创新想法,但我确实有我认为更好的方法。

想想你的数据。它分为组(A、B、C),每个组还有一个子组(I、II)。因此,当您绘制数据时,您需要 2 个“视觉辅助工具”:其中一个说明主要组,第二个显示子组。

一个明智的方法是按位置分隔主要组并用颜色指示子组。

因此,您可以将数据重塑为数据框 (df1),如下所示:

  group subgroup yvar
1     A        I   15
2     B        I    5
3     C        I   15
4     A       II   25
5     B       II   45
6     C       II    5

然后使用 ggplot 生成堆积条形图:

library(ggplot)
ggplot(df1, aes(x = group, y = yvar, fill = subgroup)) + geom_bar()

结果:

在此处输入图像描述

请注意,ggplot 会为您计算总数。看看这个,看看组合的 3D 条形图 + 饼图,然后问自己:哪一个最能一目了然地传达数据的关键特征?

请相信我和本论坛的数据可视化专家,我们告诉您:重要的是清晰的呈现,而不是“商业人士想要什么”。

Please suggest me if you have any other innovative idea to present such data

I don't have an innovative idea, but I do have what I think is a better way.

Think about your data. It's divided into groups (A, B, C), each of which also has a subgroup (I, II). So when you plot the data, you need 2 "visual aids": one of which illustrates the main groups and a second showing the subgroups.

A sensible way to do this is to separate the main groups by position and indicate the subgroups by colour.

So, you can reshape your data into a data frame (df1) which looks like this:

  group subgroup yvar
1     A        I   15
2     B        I    5
3     C        I   15
4     A       II   25
5     B       II   45
6     C       II    5

And then use ggplot to generate a stacked bar plot:

library(ggplot)
ggplot(df1, aes(x = group, y = yvar, fill = subgroup)) + geom_bar()

Result:

enter image description here

Note that ggplot calculates the totals for you. Look at that, look at your combined 3D bar + pie charts and ask yourself: which one best conveys the key features of the data, at a glance?

Please trust me and the data visualization experts on this forum when we tell you: what matters is clear presentation, not "what business people want."

千と千尋 2025-01-01 13:22:05

来吧,让我们一起吃馅饼吧!我建议你只选择饼图解决方案 - 无论如何都需要条形图。只需获取 plotrix 包即可。以下是我如何以饼图的形式显示 6 个数字的矩阵。

plot(1:5,type="n",main="Pie charts are evil",xlab="",ylab="",axes=FALSE)#empty plot
require(plotrix)
main_col <- c("#ff0000","#80ff00","#00ffff")#nice colors
main_pie <- floating.pie(3,3,c(40,50,20), col=main_col,radius=1)#your big pie
#here are your small pies with labels using plotrix functions
small_col <- c("black","white")
small_lab <- c("I","II")
A <- floating.pie(3.8,4.5,c(15,5), col=small_col,radius=0.2)
pie.labels(3.8,4.5,A,small_lab,border=F,radius=0.3,cex=0.8)
B <- floating.pie(1.7,2,c(15,25), col=small_col,radius=0.2)
pie.labels(1.7,2,B,small_lab,border=F,radius=0.3,cex=0.8)
C <- floating.pie(4.3,2,c(5,45), col=small_col,radius=0.2)
pie.labels(4.3,2,C,small_lab,border=F,radius=0.3,cex=0.8)
#and finally very useful legend
legend("right",legend=c("A","B","C"),col=main_col,bty="n",pch=15)

在此处输入图像描述

Come on, lets go wild with the pies! I suggest you just go for pie-only solution - who needs bar charts anyway. Just get plotrix package. Here is how I would display matrix of 6 numbers in the form of pie charts.

plot(1:5,type="n",main="Pie charts are evil",xlab="",ylab="",axes=FALSE)#empty plot
require(plotrix)
main_col <- c("#ff0000","#80ff00","#00ffff")#nice colors
main_pie <- floating.pie(3,3,c(40,50,20), col=main_col,radius=1)#your big pie
#here are your small pies with labels using plotrix functions
small_col <- c("black","white")
small_lab <- c("I","II")
A <- floating.pie(3.8,4.5,c(15,5), col=small_col,radius=0.2)
pie.labels(3.8,4.5,A,small_lab,border=F,radius=0.3,cex=0.8)
B <- floating.pie(1.7,2,c(15,25), col=small_col,radius=0.2)
pie.labels(1.7,2,B,small_lab,border=F,radius=0.3,cex=0.8)
C <- floating.pie(4.3,2,c(5,45), col=small_col,radius=0.2)
pie.labels(4.3,2,C,small_lab,border=F,radius=0.3,cex=0.8)
#and finally very useful legend
legend("right",legend=c("A","B","C"),col=main_col,bty="n",pch=15)

enter image description here

遥远的她 2025-01-01 13:22:05

我同意其他一些回答者的观点,即饼图可能不是绘制此类数据的最佳方式。我更愿意使用每个子类别都有一条线的线图。

快速谷歌搜索“R 创建饼图”线索显示此链接为第一个点击。它显示了创建饼图的大量选项。类似的 google for barcharts 会指向此链接

关于组合绘图,我会单独创建绘图并使用绘图程序(例如 gimp 或 inkscape)将它们组合起来。当您不想多次创建此类绘图时,这尤其有效。

I agree with some of the other answerers that a piechart may not be the best way of graphing this kind of data. I'd much rather go for a line plot with a line for each of the subcategories.

A quick google for "R create pie charts" lead showed this link as the first hit. It shows a plethora of options to create piecharts. A similar google for barcharts lead to this link.

In regard to combining the plots, I'd create the plots seperately and combine them using a drawing program such as the gimp or inkscape. This is especially effective when you do not want to create these kinds of plots dozens of times.

时光与爱终年不遇 2025-01-01 13:22:05

你有没有想过使用 python/matplotlib ?同样免费且良好,并且具有(a)饼图和(b)在其他图表上叠加图表的选项,这可能会满足您的需求。

http://matplotlib.sourceforge.net/gallery.html

或者你可以做一个分解饼图显示子类别:

http://matplotlib.sourceforge.net/examples/pylab_examples/pie_demo.html

Have you thought of using python/matplotlib? Equally free and good, and has options for (a) pie chart and (b) overlaying graphs on other graphs, which might do what you want.

http://matplotlib.sourceforge.net/gallery.html

Or you could do an exploded pie chart to show subcategories:

http://matplotlib.sourceforge.net/examples/pylab_examples/pie_demo.html

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