使用以下数据:
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"))
这可行,但是我想在图表上的元素上包含文本标签(“显示 fe 被盗、丢失”等)
但是,当我这样做时:
g + geom_text(x = Category, y = Subcategory, label = Weight)
我收到以下错误:
UseMethod(“rescale”)中的错误:没有适用于“rescale”的适用方法应用于“character”类的对象
关于这里出了什么问题的任何想法?