R,ggplot2,

时间:2018-07-04 08:06:28

标签: r ggplot2

当我的日期变量YEAR处于会计年度,例如2010/112011/122012/13等时,YEAR是因子变量{{ 1}}是字符变量,而variable是数字变量

R给我一个错误消息:

value

我的代码如下:

加载数据和所需的程序包后:

geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?

1 个答案:

答案 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