如何从尼尔森输出图表?

发布于 2024-11-26 19:24:59 字数 890 浏览 0 评论 0 原文

我今天在 engadget 上看到了 Nielsen 制作的一个有趣的图表:

http://www.engadget.com/2011/07/28/nielsen-android-leads-us-smartphone-market-with-39-percent-shar/

原始来源:<一个href="http://blog.nielsen.com/nielsenwire/online_mobile/in-us-smartphone-market-android-is-top-operating-system-apple-is-top-manufacturer/?utm_source=feedburner&utm_medium= feed&utm_campaign=Feed%3A+NielsenWire+%28Nielsen+Wire%29" rel="nofollow">http://blog.nielsen.com/nielsenwire/online_mobile/in-us-smartphone-market-android-is-top-operating-system-apple-is-top-manufacturer/?utm_source=feedburner& ;utm_medium=feed&utm_campaign=Feed%3A+NielsenWire+%28Nielsen+Wire%29

我会如果可能的话,希望有人复制它并显示 R 代码。基本包或 ggplot2 会很棒。

我喜欢这些盒子是成比例的,这是一个关键特征:)

谢谢!

I saw an interesting chart on engadget today made by Nielsen:

http://www.engadget.com/2011/07/28/nielsen-android-leads-us-smartphone-market-with-39-percent-shar/

original source: http://blog.nielsen.com/nielsenwire/online_mobile/in-u-s-smartphone-market-android-is-top-operating-system-apple-is-top-manufacturer/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+NielsenWire+%28Nielsen+Wire%29

I'd love for someone to replicate it if possible and show the R code. Basic packages or ggplot2 would be great.

I like that the boxes are proportional, that's a key feature :)

Thanks!

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

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

发布评论

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

评论(2

无声静候 2024-12-03 19:24:59

您可以在 R 中以“马赛克图表”的名称找到多种实现。例如:

require("vcd")
data(HairEyeColor)
mosaic(HairEyeColor, shade = TRUE)

在此处输入图像描述

例如 quickR,但搜索 R 图库也是一个不错的选择。

在 ggplot2 中,您可以在 learnr 的博客上找到示例。

我还在 ggplot2 中做了一些调整,请参阅下面的附图。它是匈牙利语的,但如果你有兴趣,我可以清理代码并发布在某个地方。

在此处输入图像描述


更新:我已根据评论搜索了我的旧脚本并上传了它到 pastebin。抱歉,没有代码清理,而且非常混乱,因为我必须从 SPSS 数据文件中进行大量报告来弥补,但我希望你可以使用它。使用方法很简单:加载所有函数(例如:使用 source(...) 函数运行 R 中的所有行),并且可以通过指定两个变量名称生成任何数据框的马赛克图在ggMosaicChart()的参数中。绘图将保存到工作目录中的 png 文件中(在 R 中无法轻松调整绘图的大小,因为需要进行大量手动调整才能很好地排列文本)。

我已将字符串翻译成英语,这是 mtcars 数据集的基本示例(包含在上面的代码中):

在此处输入图像描述

显示每个单元格的计数、行百分比和列百分比以及 Pearson 残差。

You can find several implementations in R under the name of 'mosaic chart'. E.g.:

require("vcd")
data(HairEyeColor)
mosaic(HairEyeColor, shade = TRUE)

enter image description here

Se some examples on e.g. quickR, but searching the R graph gallery is also a good option.

In ggplot2, you can find a sample on learnr's blog.

I have also done some tweaks in ggplot2, please find the attached plot below. It is in Hungarian, but if you are interested, I could clean up the code and post is somewhere.

enter image description here


UPDATE: I have searched for my old script based on comment and uploaded it to pastebin. Sorry, no code clean up and it is quite messy, as I had to make it up for mass reporting from SPSS data files, but I hope you could use it. The usage is simple: load all functions (e.g.: run all lines in R with the source(...) function), and you could generate a mosaic chart of any data frame by specifying two variable names in the parameters of ggMosaicChart(). The plot will be saved to a png file in the working directory (no easy resize in R of the plot as lots of manual tweaks are done to arrange text nicely).

I have translated the strings to English, a basic example (included in the above code) of the mtcars data set:

enter image description here

Count, row- and column percent and also Pearson residuals are shown for each cell.

娇柔作态 2024-12-03 19:24:59

它称为树状图。 R 项目有名为“treemap”或“portfolio”的包。操作方法如下: http:// Flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/

It's called treemap. R project has packages named "treemap" or "portfolio" for it. Here is how to do: http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/

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