我执行了以下代码以可视化我的分类变量:
PDfFont font = DocumentUtil.setFont();
这让我出错了:
错误:
p3 <- ggplot(combi %>% group_by(Item_Type) %>% summary(count = n())) + geom_bar(aes(Item_Fat_Content, count), stat = "Identity", fill = "coral1") + xlab("") + geom_label(aes(Item_Fat_Content, count, label = count), vjust = 0.5 ) + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + ggtitle("Item Type")
必须是数据帧或其他可强制执行的对象data
,而不是带有类表的S3对象
答案 0 :(得分:1)
正如Pogibas所说:
summary
替换为summarize
。请参见下面的代码(带有combi
数据帧模拟); left_join
设为可执行代码)。请参见下面的代码:
library(ggplot2)
library(dplyr)
n <- 10
m <- 3
combi <- data.frame(
Item_Type = sample(letters[1:m], n, replace = TRUE),
Item_Fat_Content = abs(rnorm(n))
)
ggplot(combi %>%
group_by(Item_Type) %>%
summarise(count = n()) %>% left_join(combi)) +
geom_bar(aes(Item_Fat_Content, count), stat = "Identity", fill = "coral1") +
xlab("") +
geom_label(aes(Item_Fat_Content, count, label = count), vjust = 0.5 ) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ggtitle("Item Type")