Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何制作平面华夫饼图,从左上角填充每个箱子_R_Ggplot2_Waffle Chart - Fatal编程技术网

R 如何制作平面华夫饼图,从左上角填充每个箱子

R 如何制作平面华夫饼图,从左上角填充每个箱子,r,ggplot2,waffle-chart,R,Ggplot2,Waffle Chart,我正试图创建一个3x4格的垃圾箱,每个垃圾箱中都有我的数据观察值。我已经走到一半了: library(ggplot2) type <- c('daily', 'daily', 'habit', 'habit', 'habit', 'seasonal', 'seasonal', 'year-long', 'year-long', 'year-long', 'year-long', 'year-long') status <- c('complete', 'incomplete', 'p

我正试图创建一个3x4格的垃圾箱,每个垃圾箱中都有我的数据观察值。我已经走到一半了:

library(ggplot2)
type <- c('daily', 'daily', 'habit', 'habit', 'habit', 'seasonal', 'seasonal', 'year-long', 'year-long', 'year-long', 'year-long', 'year-long')
status <- c('complete', 'incomplete', 'push', 'push', 'incomplete', 'complete', 'complete', 'complete', 'complete', 'push', 'push', 'incomplete')
results <- data.frame(type, status)

ggplot(results) +
  geom_dotplot(aes(x=status, y=type), binwidth=.2) +
  facet_grid(vars(type))
库(ggplot2)

type目前,该华夫饼包存在一个开放性问题,它阻止了我按照我想要的方式生成图表(得到一个错误“invalid'times'argument”),在状态和类型中使用facet_网格

或者,我们可以做一些数据准备来创建类似的东西

rows <- 4
cols <- 4

results %>%
  arrange(status, type) %>%
  group_by(status, type) %>%
  mutate(num = row_number(),
         x_pos = (num - 1) %/% rows,
         y_pos = rows - (num - 1) %% rows - 1) %>%

  ggplot(aes(x = x_pos, y = y_pos)) +
  geom_tile(fill = "black", color = "white") +
  coord_equal(xlim = c(0, cols) - 0.5,
              ylim = c(0, rows) - 0.5) +
  facet_grid(vars(type), vars(status)) +
  theme_light() +
  theme(panel.grid = element_blank(),
        axis.text = element_blank())
行%
分组依据(状态、类型)%>%
mutate(num=行数(),
x_pos=(num-1)%/%行,
y_pos=行-(num-1)%%行-1)%%>%
ggplot(aes(x=x_位置,y=y_位置))+
geom_瓷砖(填充=“黑色”,颜色=“白色”)+
坐标等于(xlim=c(0,cols)-0.5,
ylim=c(0,行)-0.5)+
刻面网格(变量(类型)、变量(状态))+
主题灯()+
主题(panel.grid=element\u blank(),
axis.text=元素_blank())

目前,该华夫饼包存在一个漏洞,它阻止我按照我想要的方式生成图表(获取错误“invalid'times”参数),在状态和类型上使用facet_网格

或者,我们可以做一些数据准备来创建类似的东西

rows <- 4
cols <- 4

results %>%
  arrange(status, type) %>%
  group_by(status, type) %>%
  mutate(num = row_number(),
         x_pos = (num - 1) %/% rows,
         y_pos = rows - (num - 1) %% rows - 1) %>%

  ggplot(aes(x = x_pos, y = y_pos)) +
  geom_tile(fill = "black", color = "white") +
  coord_equal(xlim = c(0, cols) - 0.5,
              ylim = c(0, rows) - 0.5) +
  facet_grid(vars(type), vars(status)) +
  theme_light() +
  theme(panel.grid = element_blank(),
        axis.text = element_blank())
行%
分组依据(状态、类型)%>%
mutate(num=行数(),
x_pos=(num-1)%/%行,
y_pos=行-(num-1)%%行-1)%%>%
ggplot(aes(x=x_位置,y=y_位置))+
geom_瓷砖(填充=“黑色”,颜色=“白色”)+
坐标等于(xlim=c(0,cols)-0.5,
ylim=c(0,行)-0.5)+
刻面网格(变量(类型)、变量(状态))+
主题灯()+
主题(panel.grid=element\u blank(),
axis.text=元素_blank())

您尝试使用华夫饼的代码是什么?你还能画出想要的结果吗?
ggplot(results,aes(fill=type,values=sum(as.integer(status)))+geom_-waffle()+facet_-wrap(status~type)+coord_-equal()
不确定我的结果在这里是什么……也遇到了下面提到的
waffle
包的问题(“带有
facet\u grid
的'times'参数无效)您使用
waffle
包尝试的代码是什么?你还能画出想要的结果吗?
ggplot(results,aes(fill=type,values=sum(as.integer(status)))+geom_-waffle()+facet_-wrap(status~type)+coord_-equal()
不确定我的结果在这里是什么……也遇到了下面提到的
waffle
包的问题(“使用
facet\u grid
的'times'参数无效)谢谢!正是我需要的。我在想,我需要在数据中添加一些东西,以使其更简单,但无法解决它。谢谢!正是我需要的。我在想,我需要在数据中添加一些东西,以使其更简单,但无法理解。