用R中的图表可视化交叉表 [英] visualizing crosstab tables with a plot in R

查看:672
本文介绍了用R中的图表可视化交叉表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了在excel中生成的图,我想知道R是否也可以做到。

I saw a plot generated in excel and I was wondering if R could also do it.

交叉表的可视化图表,将星期几与当天的首选餐进行比较,并计算属于这些类别的人数。

This picture is essentially a visualization of a crosstab table comparing the days of the week to preferred meals on that day and counting the number of people that fall within those categories.

一些R气泡图,但我还没有看到这样的图表。有人可以将我指向一个软件包或网站,该软件包或网站解释了如何制作这样的情节吗?

I've read up on some R bubble charts but I have yet to see one like this. Can someone point me to a package or a website that explains how I can make a plot like this one?

推荐答案

使用Hadley Wickham的 ggplot2

Using Hadley Wickham's ggplot2:

library(ggplot2)                           

# Set up the vectors                           
days <- c("Mon","Tues","Wed","Thurs","Fri")
slots <- c("Coffee/Breakfast","Lunch","Happy Hour","Dinner")

# Create the data frame
df <- expand.grid(days, slots)
df$value <- c(1,1,1,1,2,1,1,NA,NA,1,4,4,7,4,1,5,6,14,5,1)    

#Plot the Data
g <- ggplot(df, aes(Var1, Var2)) + geom_point(aes(size = value), colour = "green") + theme_bw() + xlab("") + ylab("")
g + scale_size_continuous(range=c(10,30)) + geom_text(aes(label = value))

您是否在乎轴线穿过圆弧es?另外,绿色略有不同,标签文字是黑色而不是白色。

Do you care that the axis lines go through the circles? Also, the greens are slightly different and the label text is black instead of white.

这篇关于用R中的图表可视化交叉表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆