R - 使用包 ggmosaic 时出错
R - Error in using the package ggmosaic
我正在使用新包 ggmosaic
来绘制带有 ggplot2
的马赛克图。
我使用的数据集中的一个变量出现错误 "Computation failed in stat_mosaic()
"。问题似乎位于变量的内容周围,更准确地说是围绕 ]
的处理,因为当我用另一个符号(如 )
.
替换它时它起作用了
一个简单的例子:
# Parameters
library(ggplot2)
library(ggmosaic)
set.separators(c(":", ";", "|")) # cf. ggmosaic documentation
# Plot OK
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(TheGroup, TheRange), fill = TheGroup), na.rm = TRUE) +
theme(axis.text.x = element_text(angle = 0, hjust = .1)) +
labs(x = "TheRange", y = "TheGroup")
# Plot NOK
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(TheRange, TheGroup), fill = TheRange), na.rm = TRUE) +
theme(axis.text.x = element_text(angle = 0, hjust = .1)) +
labs(x = "TheGroup", y = "TheRange")
我的数据框的子集带有变量:
df <- structure(list(TheRange = structure(c(1L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 3L, 3L, 2L, 3L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 2L, 3L, 2L,
1L, 2L, 2L, 3L, 1L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 1L, 3L, 1L, 2L,
1L, 3L, 3L, 1L, 3L),
.Label = c("(0,30]", "(30,50]", "(50,100]"), class = "factor"),
TheGroup = c("Groupe 2", "Groupe 1", "Groupe 2",
"Groupe 1", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 1",
"Groupe 1", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 1", "Groupe 1",
"Groupe 2", "Groupe 1", "Groupe 1", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2")),
.Names = c("TheRange", "TheGroup"),
row.names = c(1L, 2L, 3L, 4L, 5L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 30L,
31L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 41L, 42L, 43L, 44L, 46L,
47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L),
class = "data.frame")
该错误已在最新版本的 ggmosaic (0.1.2) 上得到纠正。
我正在使用新包 ggmosaic
来绘制带有 ggplot2
的马赛克图。
我使用的数据集中的一个变量出现错误 "Computation failed in stat_mosaic()
"。问题似乎位于变量的内容周围,更准确地说是围绕 ]
的处理,因为当我用另一个符号(如 )
.
一个简单的例子:
# Parameters
library(ggplot2)
library(ggmosaic)
set.separators(c(":", ";", "|")) # cf. ggmosaic documentation
# Plot OK
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(TheGroup, TheRange), fill = TheGroup), na.rm = TRUE) +
theme(axis.text.x = element_text(angle = 0, hjust = .1)) +
labs(x = "TheRange", y = "TheGroup")
# Plot NOK
ggplot(data = df) +
geom_mosaic(aes(weight = 1, x = product(TheRange, TheGroup), fill = TheRange), na.rm = TRUE) +
theme(axis.text.x = element_text(angle = 0, hjust = .1)) +
labs(x = "TheGroup", y = "TheRange")
我的数据框的子集带有变量:
df <- structure(list(TheRange = structure(c(1L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 3L, 3L, 2L, 3L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 2L, 3L, 2L,
1L, 2L, 2L, 3L, 1L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 1L, 3L, 1L, 2L,
1L, 3L, 3L, 1L, 3L),
.Label = c("(0,30]", "(30,50]", "(50,100]"), class = "factor"),
TheGroup = c("Groupe 2", "Groupe 1", "Groupe 2",
"Groupe 1", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 2", "Groupe 1",
"Groupe 1", "Groupe 1", "Groupe 2", "Groupe 1", "Groupe 1", "Groupe 1",
"Groupe 2", "Groupe 1", "Groupe 1", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2",
"Groupe 2", "Groupe 2", "Groupe 2", "Groupe 2")),
.Names = c("TheRange", "TheGroup"),
row.names = c(1L, 2L, 3L, 4L, 5L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 30L,
31L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 41L, 42L, 43L, 44L, 46L,
47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L),
class = "data.frame")
该错误已在最新版本的 ggmosaic (0.1.2) 上得到纠正。