2013-12-19 46 views
14

我看到了一個在Excel中生成的圖表,我想知道R是否也可以這樣做。 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在R中可視化交叉表的圖表

該圖片實質上是一個交叉表的可視化,它將當天的日子與當天的優先餐點進行比較,並計算屬於這些類別的人數。

我讀過一些R氣泡圖表,但我還沒有看到這樣的一個。有人可以指我一個包或一個網站,解釋我可以如何做一個這樣的情節?

+0

也許[我的答案](http://stats.stackexchange.com/a/34778/13474)可能會幫助你。 – A5C1D2H2I1M1N2O1R2T1

回答

16

使用哈德利韋翰的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

你關心的軸線經過圓?此外,果嶺略有不同,標籤文字是黑色而不是白色。

+0

這是完美的,謝謝。只有一個問題,有沒有辦法改變形狀,圓周邊看起來有點「豎起」。該功能可以使它成爲一個光滑的圓圈?如果不是那麼沒關係 – CadisEtRama

+1

使用ggsave可以設置每英寸點數。默認值是72dpi,使用'ggsave(file =「filename.png」,dpi = 300)'''''''''''''''''''''',您可以將dpi的值設置爲更高的值。這可能會解決您的問題。 – Jaap