The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
stack_data <- diamonds %>%
group_by(color, cut) %>%
summarise(mean_price = mean(price), .groups = "drop")%>%
mutate(mean_price = round(mean_price,1)) #保留一位小数
ggplot(stack_data, aes(x = color, y = mean_price, fill = cut)) +
geom_col(position = "stack") +
geom_text(aes(label=mean_price),position=position_stack(0.5),size=3)+
scale_fill_brewer(palette = "Paired") +
labs(
title = "颜色与切工组合的平均价格堆积图",
x = "颜色等级",
y = "平均价格(美元)"
)