使用以下数据:
Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving")
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract")
Weight <- c(10,20,13,40,20)
Duration <- as.character(c(0.2,0.4,0.5,0.44,0.66))
Silence <- as.character(c(0.1,0.3,0.25,0.74,0.26))
df <- data.frame(Category, Subcategory, Weight, Duration, Silence)
我用它来创建以下马赛克图:
library (ggplot2)
library (ggmosaic)
g <- ggplot(data = df) +
geom_mosaic(aes(weight = Weight, x = product(Category), fill = Duration),
offset = 0, na.rm = TRUE) +
theme(axis.text.x = element_text(angle = -25, hjust = .1)) +
theme(axis.title.x = element_blank()) +
scale_fill_manual(values = c("#e8f5e9", "#c8e6c9", "#a5d6a7", "#81c784", "#66bb6a"))
这个图表可以展示数据,但我希望在图表元素上包含文本标签(例如“显示被盗、丢失的费用”等)。
但是,当我这样做时:
g + geom_text(x = Category, y = Subcategory, label = Weight)
我遇到了以下错误:
你有什么想法,是什么导致了这个问题?运行 UseMethod("rescale") 时出错:没有可适用于 "character" 类型对象的 'rescale' 方法