服务热线
178 0020 3020
R2-03作业之ggplot2画柱状图
任务1:
library(ggplot2)
library(reshape)
data <- read.csv("D:/Study/R/R2-第3期任务/3/R2-3.1.csv", header = T)
data <- melt(data,id.vars ='Products',
measure.vars =c("Q1th", 'Q2nd', 'Q3rd','Q4th'))
data
ggplot(data, aes(x=variable, y= value, fill = Products))+
geom_bar(stat="identity", position="dodge", color= "black") +
labs(x="Time", y="Index")+ ggtitle("R2-03-5")+
scale_fill_wsj("rgby")+theme_wsj(color="blue")+
ggsave('E:/PNG/R2/R2-03-5.png',width=6,height=4)
任务2:
library(ggplot2)
data2 <- read.csv("D:/Study/R/R2-第3期任务/3/R2_3_2.csv", header = T)
graph2 <- ggplot(data2, aes(社区,fill = 态度,color = 态度))+
geom_bar(position="stack",width=0.7)+
ggtitle("R2-03-6")+
labs(x="社区", y="count")+
coord_flip()+
ggsave('E:/PNG/R2/R2-03-6.png')
附件