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

这张图片本质上是交叉表的可视化,将一周中的几天与当天的首选用餐进行比较,并计算属于这些类别的人数。
我读过一些R型气泡图,但我还没有看到过这样的。有人能给我介绍一个软件包或网站来解释我如何制作这样的情节吗?
发布于 2013-12-19 13:23:13
使用Hadley Wickham的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))

你关心轴线穿过圆圈吗?此外,绿色略有不同,标签文本是黑色而不是白色。
发布于 2021-03-06 06:17:00
ggmosaic package对ggplot进行了扩展,以提供一种替代方案。

library(ggplot2)
library(ggmosaic)
# Set up the vectors
days <- c("Mon","Tues","Wed","Thurs","Fri")
slots <- c("Coffee/Breakfast","Lunch","Happy Hour","Dinner")
# Create the comporessed data frame
df <- expand.grid(days, slots, stringsAsFactors = TRUE)
df$value <- c(1,1,1,1,2,1,1,0,0,1,4,4,7,4,1,5,6,14,5,1)
df.expanded <- df[rep(row.names(df), df$value), 1:2]
#Plot the Data
ggplot(data = df.expanded) +
geom_mosaic(aes(x = product(Var2,Var1), fill = Var2)) +
ggsave("mosaic.png")https://stackoverflow.com/questions/20673584
复制相似问题