当我的日期变量YEAR
处于会计年度,例如2010/11
,2011/12
,2012/13
等时,YEAR
是因子变量{{ 1}}是字符变量,而variable
是数字变量
R给我一个错误消息:
value
我的代码如下:
加载数据和所需的程序包后:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
答案 0 :(得分:0)
您提供了fill
的美感,但geom_line需要color
。
应该是
data<-mutate(data,pcosr=Internal_Revenue/Total_Income*100,
pcgrants=Grants/Total_Income*100)
data<-data %>%
select(YEAR,pcosr, pcgrants,Local_Bodies) %>%
gather(key="variable",value="value",-YEAR, -Local_Bodies)
data<-subset(data,Local_Bodies=="vdc")
ggplot(data,aes(x=YEAR,y=value,color=variable))+geom_line()+
labs( y="Percentage",
color=NULL) + # title and caption
scale_color_manual(labels = c("percentage OSR", "percentage Grants"),
values = c("percentage OSR"="#00ba38",
"percentage Grant"="#f8766d")) + # line color
theme(axis.text.x = element_text(angle = 90, vjust=0.5, size = 8), # rotate
x axis text
panel.grid.minor = element_blank()) # turn off minor grid