Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visualizing crosstab tables with a plot in R

Tags:

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 preffered meals on that day and counting the number of people that fall within those categories

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.

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?

like image 557
CadisEtRama Avatar asked Dec 19 '13 04:12

CadisEtRama


People also ask

What is Crosstable function in R?

Crosstable is a package centered on a single function, crosstable , which easily computes descriptive statistics on datasets. It can use the tidyverse syntax and is interfaced with the package officer to create automatized reports.

What is Crosstabulation table?

For a precise reference, a cross-tabulation is a two- (or more) dimensional table that records the number (frequency) of respondents that have the specific characteristics described in the cells of the table. Cross-tabulation tables provide a wealth of information about the relationship between the variables.


1 Answers

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))

enter image description here

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.

like image 143
Tommy O'Dell Avatar answered Oct 06 '22 22:10

Tommy O'Dell