如何从尼尔森输出图表?
我今天在 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 会很棒。
我喜欢这些盒子是成比例的,这是一个关键特征:)
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 R 中以“马赛克图表”的名称找到多种实现。例如:
例如 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.:
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.
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 ofggMosaicChart()
. 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:Count, row- and column percent and also Pearson residuals are shown for each cell.
它称为树状图。 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/