我正在尝试制作一组曲线图,表示产品(X)和消费者投诉数量(y)之间的关系。我想知道如何使用fct_relevel来改变绘图的顺序。它们现在是按字母顺序排列的,但我希望它们按日历年的顺序排列。此外,我使用scale_fill_manual更改了绘图的颜色,但它似乎不起作用。如有任何帮助,我们不胜感激!
This is the output I have for now.
This is the output I am looking for.
library(tidyverse)
library(forcats)
cc <- read.csv('C:\\Users\\Emma Ping\\Desktop\\STAT 405\\consumer_complaints.csv')
cc1 <- cc[cc$Year == "2015" & cc$submitted_via == "Web", ]
cbPalette <- c("#CC79A7", "#D55E00", "#56B4E9", "#F0E442", "#009E73", "#0072B2", "#999999", "#E69F00")
p4 <- ggplot(cc1, aes(reorder(product, -table(product)[product]))) +
geom_bar() +
ggtitle("Number of Monthly Web Consumer Complaints for the year 2015")+
xlab("Data Products") +
ylab("Number of Consumer Web Complaints")+
guides(fill = "none")+
scale_fill_manual(values = cbPalette)+
facet_wrap(~Month, ncol=4, scales="free_y")+
theme(axis.text.x = element_text(angle = 90, hjust=1, size=12))
p4 发布于 2021-07-02 00:57:19
有几个内置常量,month.name就是其中之一。看起来您的月份具有相同的拼写,所以这应该是有效的:
cc1$Month <- factor(cc1$Month, levels=month.name)请注意,它不是months.names或month.names。
https://stackoverflow.com/questions/68213995
复制相似问题